在.h文件中没有获得当前用户位置
#import <MapKit/MapKit.h>
@interface FirstViewController : UIViewController <MKMapViewDelegate,MKReverseGeocoderDelegate,CLLocationManagerDelegate>
{
}
在.m文件
-(void)viewDidLoad
{
CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[super viewDidLoad];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"locationManager:%@ didFailWithError:%@", manager, error);
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
MKPlacemark * myPlacemark = placemark;
NSString *kABPersonAddressCityKey;
NSString *city = [myPlacemark.addressDictionary objectForKey:(NSString*) kABPersonAddressCityKey];
lblAddress.text = city;
NSLog(@"city detail is:--> %@",city);
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error);
}
这就是我所做的得到用户的当前位置&打印它的代码标签。
但CLLocationManager
委托方法(这是写在上面)不叫&我无法获得当前地址。
请帮我一把。
我在哪里犯错...?引导我。
谢谢。
什么是错误? (顺便说一句,我想你是在泄漏你的反向地理编码器。) – 2012-07-13 07:15:28
reverseGeocoder: didFailWithError:错误域= PBRequesterErrorDomain代码= 6001“操作无法完成(PBRequesterErrorDomain错误6001.)” –
2012-07-13 07:19:33
似乎很好对我来说 - 你看到http://stackoverflow.com/questions/3031038/reversegeocoder-fail-error-in-mapkit? – 2012-07-13 07:23:35