2

位置更新调用了三次,位置确实失败并出现错误即使没有接收到数据也没有调用如何避免调用位置更新三次并且调用确实失败并出现错误,因为没有接收到数据?


我不考虑互联网连接

4

3 回答 3

2

How to avoid calling three times location did update?

for ios location update delegate may call several time depend upon on speed not three times so use bool variable to indicate

How to call did fail with error for no internet connection?

you have set location manger delegate with self

于 2013-10-24T05:44:24.240 回答
0

如何避免调用三次位置更新?

在此方法中将位置管理器的委托设置为 nil。

由于没有互联网连接,如何调用失败并出现错误?

为什么要叫它?位置可能来自三个来源:GPS 无线电、蜂窝和 WiFi,但不是来自互联网。

于 2013-10-24T05:26:26.987 回答
0

LocationManager didUpdateToLocation 总是检查位置的变化。如果它找到多个位置,它将多次调用。你可以用不同的方式避免它。但是,如果用户更改他当前的位置,这不会更新位置。

您可以使用此代码来获取位置并继续进行。

-(void)getLocation{

locationManager = [[CLLocationManager alloc] init] ;
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

// [locationManager startUpdatingLocation]; 评论以避免多次调用,或者您可以说更新当前位置 CLLocation *newLocation=[locationManager location]; CLGeocoder * geoCoder = [[CLGeocoder alloc] init]; [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {

    NSString * location = ([placemarks count] > 0) ? [[placemarks objectAtIndex:0] locality] : @"Not Found";
    NSLog(@"location:%@",location);
    NSLog(@"lat:%f",locationManager.location.coordinate.latitude);
    NSLog(@"long:%f",locationManager.location.coordinate.longitude);
}];

}

于 2013-11-21T08:39:27.007 回答