如何在ios中获取终止状态下每200米的位置
我正在尝试获取应用程序终止状态下的用户位置。我是通过如何在ios中获取终止状态下每200米的位置,ios,location,cllocationmanager,suspend,Ios,Location,Cllocationmanager,Suspend,我正在尝试获取应用程序终止状态下的用户位置。我是通过startMonitoringSignificantLocationChanges来完成这项工作的,但它会在3公里或5分钟后给出位置。因此无法正确创建路线。请指导我怎么做 if (_anotherLocationManager) [_anotherLocationManager stopMonitoringSignificantLocationChanges]; self.anotherLocationManager = [[CLL
startMonitoringSignificantLocationChanges
来完成这项工作的,但它会在3公里或5分钟后给出位置。因此无法正确创建路线。请指导我怎么做
if (_anotherLocationManager)
[_anotherLocationManager stopMonitoringSignificantLocationChanges];
self.anotherLocationManager = [[CLLocationManager alloc]init];
_anotherLocationManager.delegate = self;
_anotherLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_anotherLocationManager.activityType = CLActivityTypeOtherNavigation;
if(IS_OS_8_OR_LATER) {
[_anotherLocationManager requestAlwaysAuthorization];
}
[_anotherLocationManager startMonitoringSignificantLocationChanges];
您将无法获得200米的粒度,也无法通过重要的位置监控实现连续跟踪 您是否在文档中看到这些注释: 重大更改位置服务仅在以下情况下提供更新: 设备的位置发生了重大变化,例如 500米或更高 如果GPS水平精度对您的应用程序不重要,并且您不需要 连续跟踪,您可以使用重大更改位置 服务
我自己解决了我的问题 创建一个locationManager对象并按如下方式分配它
self.locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
_locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; // setting the accuracy
[self.locationManager requestAlwaysAuthorization];
if([self.locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]) {
[self.locationManager setAllowsBackgroundLocationUpdates: YES];
}
self.locationManager.distanceFilter = 20.0;
[self.locationManager startMonitoringSignificantLocationChanges];
self.locationManager.activityType=CLActivityTypeAutomotiveNavigation;
[self.locationManager startUpdatingLocation];
self.locationManager.pausesLocationUpdatesAutomatically = YES;
self.locationManager.delegate = self;
现在设置位置管理器委托方法
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
{
if (newLocation.speed>7){
// here you got location, i settled speed 7 for my convenience.
}
if (newLocation.horizontalAccuracy <= self.locationManager.desiredAccuracy) {
//Desired location Found
[self.locationManager stopUpdatingLocation ];
}
}
-(void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation{
{
如果(新位置速度>7){
//这是你的位置,为了方便我设定了速度7。
}
如果(newLocation.horizontalAccurance使用地理围栏实现相同的效果
- 创建半径为200mtr的地理围栏
- 默认情况下,notifyOnExit为true
- 执行LocationManager的委派
didExitRegion
- 对于终止状态,应用程序将与didFinishLaunchingWithOptions中的
UIApplication.LaunchOptionKey.location
- 在Location launch key上创建Location Manager对象的实例,您将获得该位置退出的区域,并在每个出口上继续创建200mtr围栏
至少添加您的代码……否则很难理解!请看我读过的这篇文章。但应用程序即使在500英里内也不工作,工作时间超过3公里或10分钟。不正确,文档说明不同:返回当前位置修复后,接收方仅在检测到用户位置发生重大变化时才会生成更新事件。它不依赖distanceFilter属性中的值来生成事件