0
 CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(27.941761 , -82.171537);

    MKReverseGeocoder *reverseGeocoder =[[MKReverseGeocoder alloc] initWithCoordinate:coordinate];
    NSLog(@"%g",coordinate.latitude);
    NSLog(@"%g",coordinate.longitude);
    reverseGeocoder.delegate = self;
    [reverseGeocoder start];
//????????????????????????????????????????????????????????????????????????

}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
NSLog(@"MKReverseGeocoder has failed.");
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark            *)placemark{

NSLog(@"current place is :%@",placemark);
}

when i use the Handwritten coordinate, reverseGeocoding failed. but when i use the - coordinate geted from (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation, successed. why?

1 Answer 1

1

When I dropped your code into a test project, it worked perfectly fine for me:

2013-08-16 23:45:55.966 TestMapApp[11261:a0b] 27.9418
2013-08-16 23:45:55.967 TestMapApp[11261:a0b] -82.1715
2013-08-16 23:45:57.831 TestMapApp[11261:a0b] current place is :6015 W Farkas And Turkey Creek Rd, Plant City, FL  33567, United States @ <+27.94176100,-82.17153700> +/- 0.00m

Here is what I think is going wrong. You're using ARC and not saving your "reverseGeocoder" anywhere (like in an ivar or a property), so as soon as the function where you created "reverseGeocoder" finishes, ARC releases it.

A couple other things:

If there is an error parameter available to you in delegate methods, you should make use of them. Like this:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
    NSLog(@"MKReverseGeocoder has failed with error %@.", [error localizedDescription]);
}

And lastly & most importantly, "MKReverseGeocoder" has been deprecated since iOS 5. There's a good chance it will go away in future versions of iOS. You should try to find a replacement to use for reverse geocoding.

Not the answer you're looking for? Browse other questions tagged or ask your own question.