gpt4 book ai didi

Ios 位置更新不断获取 didUpdateLocations

转载 作者:行者123 更新时间:2023-11-29 02:11:40 31 4
gpt4 key购买 nike

应用程序启动后,我需要检查位置并将其发送到服务器。之后,我需要每公里检查一次位置。

因此,当我开始位置更新时,我将 distanceFilter 设置为 none,在接收到第一个位置时,我将其更改为 1 公里。

  //If the location update is denied
if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied)
[ self locationUpdateDenied:basicViewController];
else if ([CLLocationManager locationServicesEnabled]) {
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter=kCLDistanceFilterNone;

//In ViewDidLoad
if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[_locationManager startUpdatingLocation];
}

第一个位置接收:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{

if (locations>0) {
[_locationManager setDistanceFilter:1000.0f];

CLLocation *location = [locations objectAtIndex:0];
[User sharedInstance].latitude=location.coordinate.latitude;
[User sharedInstance].longitude=location.coordinate.longitude;
/* if (!_delegate) {
[_delegate userLocationUpdated];
}*/
}
}

它不断检查位置的问题。位置没有改变,但它仍然到达 didUpdateLocations。它就像 distanceFilter 没有改变。

我是否需要停止位置更新并使用公里距离过滤器对其进行响应?

最佳答案

根据文档,我认为您可以在启动位置服务之前设置 distanceFilter 属性,因为在使用 startUpdatingLocation 启动服务后,您将立即被调用第一个位置。

[manager setDistanceFilter:1000.0];
[manager startUpdatingLocation]; // will call didUpdateLocations immediatley
// with the current location

关于Ios 位置更新不断获取 didUpdateLocations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29229068/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com