我正在尝试获取某个位置的地标,但我得到的只是空的。这是我的头文件。
#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;
- (void)reverseGeocode;
@end
这是我的.m文件
#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方法被调用,但是NSLog没有为任何属性打印任何值。
答案 0 :(得分:1)
在NSLog中,字符串变量的占位符应为%@
(不仅仅是@
):
NSLog(@"Placemark is : %@, %@, %@, %@", [placemark country],
[placemark locality], city, street);