MKReverseGeocoder placemark is empty
I am trying to get the placemark for a location but all I am getting is empty. Here is my header file.
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface ReverseGeoCodingHelper : NSObject<MKReverseGeocoderDelegate> {
MKReverseGeocoder *reverseGeocoder;
MKPlacemark *dootPlacemark;
}
@property (nonatomic, retain) MKReverseGeocoder *reverseGeocoder;
@property (nonatomic, retain) MKPlacemark *dootPlacemark;
- (vo开发者_JS百科id)reverseGeocode;
@end
and here is my .m file
#import "ReverseGeoCodingHelper.h"
@implementation ReverseGeoCodingHelper
@synthesize reverseGeocoder,dootPlacemark;
- (void)reverseGeocode
{
if (self.reverseGeocoder != nil)
{
// release the existing reverse geocoder to stop it running
[self.reverseGeocoder release];
}
CLLocationCoordinate2D locationToLookup = {37.40091, -122.01635};
self.reverseGeocoder =
[[MKReverseGeocoder alloc]initWithCoordinate:locationToLookup];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
// MKReverseGeocoderDelegate methods
/**
Gets called when MKReverseGeocoder finds info for your coordinate,
you can retrieve info you need from corresponding fields of MKPlacemark instance you
get
*/
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark{
NSString* city = [placemark.addressDictionary valueForKey:@"City"];
NSString* street = [placemark.addressDictionary valueForKey:@"Street"];
NSLog(@"Placemark is : @, @, @, @", [placemark country], [placemark locality],
city, street);
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
NSString *errorMessage = [error localizedDescription];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Cannot obtain
address." message:errorMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
- (void)dealloc{
[reverseGeocoder release];
[super dealloc];
}
@end
didFindPlacemark method is getting called but NSLog is not printing any values for any of the attribute they all the empty.
In the NSLog, placeholders for the string variables should be %@
(not just @
):
NSLog(@"Placemark is : %@, %@, %@, %@", [placemark country],
[placemark locality], city, street);
精彩评论