我正在尝试用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";只有当我第一次得到我的值时,应用程序才有效。在第二次应用程序崩溃时。我想是因为地理编码器启动了,我想我必须有且只有一个实例在运行。(但我真的不敢相信这一点……)我可以用哪种方式来控制地理编码器的运行?
我已经看到我可以使用cllocationcoordinate2d在我的视图中建立istance地理编码器,但是...我可以用哪种方式检索newlocation.coordinate?
我已经部分解决了将地理编码器声明为类变量并检查
if (self.geocoder != nil) {
[geocoder release];
}但是...如果在我的
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark或者在我的
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailedWithError:(@NSError
*)error我释放还是取消我的对象?我觉得自己好傻:D
发布于 2010-04-14 21:42:39
不要将反向地理编码器创建为本地变量。
看看苹果公司提供的CurrentAddress示例应用程序中的MKReverseGeocoder示例。请参见MapViewController.h和MapViewController.m。
在您的代码中遵循相同的模式。
https://stackoverflow.com/questions/2637152
复制相似问题