我正在尝试使用 cllocation 和 mkreversegeocoder 检索城市名称。在我的 viewdidload 方法中,我是 cllocationmanager:
self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.desiredAccuracy = kCLLocationAccuracyBest;
[locManager startUpdatingLocation];
之后:
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation
fromLocation:(CLLocation *)oldLocation {
//some code to retrieve my information
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc]
initWithCoordinate:newLocation.coordinate ];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark
{
MKPlacemark *myPlacemark = placemark;
citta.text = [placemark locality];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
citta.text =@ "Unknow";
应用程序仅在我第一次获得我的价值时才有效。在第二次应用程序崩溃。我认为是因为地理编码器已启动,我认为我必须有一个且只有一个 istance 运行。(但我真的不喜欢这个......)。我可以通过哪种方式控制地理编码器的运行?
我已经看到我可以使用 cllocationcoordinate2d 在我的 viewdidload 中设置 mkreversegeocoder 但是......我可以通过哪种方式检索 newlocation.coordinate?
我已经部分解决了将地理编码器声明为类变量并检查
if (self.geocoder != nil) {
[geocoder release];
}
但是....如果在我的
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark
或者在我的
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailedWithError:(@NSError
*)error
我释放或取消我的对象?我觉得自己好傻 :D