我尝试使用cllocation和mkreversegeocoder撤回城市名称。 在我viewDidLoad方法我istance cllocationmanager:cllocation和mkreversegeocoder
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 [email protected] "Unknow";
应用程序仅在第一时间让我的价值。在第二次应用程序崩溃。 我认为是因为地理编码器已启动,我认为我必须有一个且只有一个运行。 (但我真的不知道这个......)。在哪种方式我可以控制地理编码器运行?
我已经看到,我可以在我的viewdidload中使用cllocationcoordinate2d istance mkreversegeocoder但是...在哪种方式我可以retreive newlocation.coordinate?
我已经部分地解决地址解析器的声明作为类变量和检查
if (self.geocoder != nil) {
[geocoder release];
}
,但....如果我
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark
或在我
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailedWithError:(@NSError
*)error
我释放或取消我的对象? 我感觉很愚蠢:D
'[无释放];'有效(无所作为),所以不需要检查。 – 2011-05-31 17:01:25