在.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