Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone cllocation和mkreversegeocoder_Iphone_Cllocationmanager_Cllocation_Mkreversegeocoder - Fatal编程技术网

Iphone cllocation和mkreversegeocoder

Iphone cllocation和mkreversegeocoder,iphone,cllocationmanager,cllocation,mkreversegeocoder,Iphone,Cllocationmanager,Cllocation,Mkreversegeocoder,我试图用cllocation和mkreversegeocoder检索城市名称。 在我的viewdidload方法中,我的istance cllocationmanager: self.locManager = [[CLLocationManager alloc] init]; locManager.delegate = self; locManager.desiredAccuracy = kCLLocationAccuracyBest; [locManager startUpdatingLoca

我试图用cllocation和mkreversegeocoder检索城市名称。 在我的viewdidload方法中,我的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 {
//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";
应用程序只有在我第一次获得价值时才起作用。在第二次应用程序崩溃时。 我想是因为geocoder启动了,我想我必须运行一个且只有一个istance。(但我真的不是舒尔的…)。我可以用哪种方式控制geocoder的运行

我已经看到我可以使用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
我释放或取消我的对象?
我觉得自己很愚蠢:不要把反向地理编码器创建为局部变量

看看苹果提供的示例应用程序中的MKReverseGeocoder示例。请参见MapViewController.h和MapViewController.m


在您的代码中遵循相同的模式。

舒尔在我以这种方式完成的最后,现在我用自动释放修改了一个不检查geocoder是否仍在运行的选项
[nil release]工作(不执行任何操作),因此无需检查。