Google does not allow one device to get its location more than once in 60 seconds, so it works with another method (an HTTP request, JSON is required instead) when (MKReverseGeocoder *) the geocoder made a FileWithError.
It works for me on 4.3.3 (3GS) and has been tested for 30-40 times, getting the user's location without failures, hope this 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"]; } }
Rocheki
source share