gpt4 book ai didi

ios - 当用户每移动 50/100 米时通知 iOS

转载 作者:行者123 更新时间:2023-12-01 17:49:59 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Update Location in Mapview Xcode

(2 个回答)


6年前关闭。




嗨,我想在位置变化 50 米(不少于这个)时调用 web 服务。我尝试过使用重大更改,但它适用于至少 500 米,并且 startupdatelocations 会一直调用。那么我如何检测设备是否从该位置移动了 50 米或 100 米。

正如许多 stackoverflow 问题中所说,我已将距离过滤器用作 50 米。但在移动到 50 米之前它不起作用,我在设备中获得了位置更新。

这里有人解释了距离过滤器 - iphone core location: distance filter how does it work?

最佳答案

这很容易。

首先写在你的ViewDidload方法分配 CLLocationManager。

这里我设置了 50M 距离。

locationManager = [[CLLocationManager alloc] init];

//there will be a warning from this line of code
[locationManager setDelegate:self];

//and we want it to be as accurate as possible
//regardless of how much time/power it takes
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

//set the amount of metres travelled before location update is made
[locationManager setDistanceFilter:50];
[locationManager requestAlwaysAuthorization];
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];

因此,每 50 米更换设备此方法称为:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
if (locations.count > 0) {
CLLocation *location = locations.lastObject;
User_latitude = [NSString stringWithFormat:@"%f",location.coordinate.latitude];
User_longitude = [NSString stringWithFormat:@"%f",location.coordinate.longitude];
NSLog(@"latitude = %f",location.coordinate.latitude);
NSLog(@"longitude = %f",location.coordinate.longitude);
[self webservice_UpdateLocation];
}
}

关于ios - 当用户每移动 50/100 米时通知 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33931077/

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