MKReverseGeocoder server returned error: 503

痞子三分冷 提交于 2019-12-03 07:45:03

I am pretty sure this is happening because you are in testing, and using the reverse geocoder too much and Google's servers know that. So, it has basically blocked you for a while. Try again later and see if it works.

You need to make sure that you are not calling the geocoder more than once every 60 seconds.

I find out!
Well, now we'll have to use CLGeocoder, but if you want still to use MKReverseGeocoder, you MUST not call [geocoder start] twice, even if the geocode object is a fresh new one! For example, DON'T do this:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
        MKReverseGeocoder *geoCoder = [[[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate] autorelease];
        geoCoder.delegate = self;
        [geoCoder start];
}

Or you'll get an arror: the location manager update position function is being called as soon as a new position is detected. As the accuracy is getting better and better, a new fresh new posistion is being sent to "didUpdateToLocation".
But creating a new object MKReverseGeocoder each time a position is found is a bad idea! So, you've got a few solutions:
- Put a boolean that is true when geocoder is started. Then in didFindPlacemark (geocoder's), you should stop the geocoder with [geocoder cancel] and set your boolean to false.
- Make geocoder variable not local and manange a [geocoder cancel] + realease and create a new one and[geocoder start] each time didUpdateToLocation is beeing called.
- Any other way to avoid [geocoder start] to be called twice

I used the first solution and never get the 503 error anymore.

For me, MKReverseGeocoder was failing with 503 far too many times. It would also fail the first time it was requested, well after 60 seconds had passed. As a result, I decided to give up using it and instead decided to access Google's API directly using NSURLRequest via a service I created that also parses the result as a JSON String using the SBJSON Framework (very useful).

From my service, I call the following URL as follows:

NSString *urlStr = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=true", coordinate.latitude, coordinate.longitude];

where coordinate is a CLLocationCoordinate2D.

I realise this is a long way around the problem, but since converting to this system I have had no issues!

It can happen at random, depending on the server's status.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!