Since iOS 4.3 (GM Seed 10M2518) I\'m getting crashes when using MKReverseGeocoder
. reverseGeocoder:didFailWithError:
gets called with an error like
I had the same issue, even though my MKReverseGeocoder
code followed one of the Apple examples (MKReverseGeocoder
as a global autorelease
variable). Also the issue appeared only on iOS 4.3 (4.0 was running no problem).
What solved the problem for me was removing the autorelease
part and releasing the MKReverseGeocoder
only in dealoc
of the view.
Google doesn't allow a single device to retrieve its location more than once within 60 sec, hence working with another method (http request instead, JSON needed) when (MKReverseGeocoder *)geocoder didFailWithError.
It works for me on 4.3.3 (3GS) and tested for 30-40 times retrieving user's location consecutively without a crash, hope it helps!
- (void) retrieveCurrentLoc {
self.geoCoder =
[[[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate] autorelease];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
NSString *fetchURL = [NSString stringWithFormat:@"http://maps.google.com/maps/geo? q=%@,%@&output=json&sensor=true", [NSString stringWithFormat:@"%f",mapView.userLocation.location.coordinate.latitude], [NSString stringWithFormat:@"%f",mapView.userLocation.location.coordinate.longitude]];
NSURL *url = [NSURL URLWithString:fetchURL];
NSString *htmlData = [NSString stringWithContentsOfURL:url];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *json = [parser objectWithString:htmlData error:nil];
NSArray *placemark = [json objectForKey:@"Placemark"];
if ([[[[[placemark objectAtIndex:0] objectForKey:@"AddressDetails"]objectForKey:@"Country"]objectForKey:@"Thoroughfare"]objectFor Key:@"ThoroughfareName"] != NULL){
currentAddress = [[[[[placemark objectAtIndex:0] objectForKey:@"AddressDetails"]objectForKey:@"Country"]objectForKey:@"Thoroughfare"]objectFor Key:@"ThoroughfareName"];}
else {
currentAddress = [[placemark objectAtIndex:0] objectForKey:@"address"];
}
}
Following on from zippo77's answer, I found best results when setting the MKReverseGeocoder delegate to nil first in -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
_reverseGeocoder.delegate = nil;
[_reverseGeocoder autorelease];
Probably you are stoping location manager before geo coder will find placemark. Do it in didFindPlacemark or for error
Same problem here, we checked various solutions and didn't work. The 503 response code is handled differently by the previous OS, you can easily notice that by sniffing the iPhone traffic.
Applications that rely on MKReverseGeocoder (like Gowalla) will make some pressure against Apple ... so I would expect a 4.3.1 hotfix coming these days. Or Google to change their SLA with Apple requests.
Make sure you don't release the reverse geocoder prematurely on failure:
Changing [_reverseGeocoder release]
to [_reverseGeocode autorelease]
in -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
fixed the problem for me.