我试图用cllocation和mkreversegeocoder检索城市名。
在我的viewdidload方法中,i istance cllocationmanager:
self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.desiredAccuracy = kCLLocationAccuracyBest;
[locManager startUpdatingLocation];
之后:
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation
fromLocation:(CLLocation *)oldLocation {
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加载mkreversegeocoder,但是…用哪种方法可以检索newlocation.coordinate?
我已经部分解决了将geocoder声明为类变量并检查
if (self.geocoder != nil) {
[geocoder release];
}
但是…如果在我
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark
或者在我的
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailedWithError:(@NSError
*)error
我释放还是取消我的对象?
我觉得自己很蠢:D