iOS9中的CLLocationManager提供错误的位置(iOS8正常) [英] CLLocationManager in iOS9 giving incorrect locations (iOS8 is OK)

查看:61
本文介绍了iOS9中的CLLocationManager提供错误的位置(iOS8正常)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从iOS9开始,我们在CCLocationManager中遇到了一些奇怪的问题。 iOS 7-8没有问题。怪异的位置会导致应用程序出错。该应用程序在开车时使用,我们有大约50位TestFlight测试用户,其中有些正在报告这些问题。


该应用程序会响应位置更新,每次更新25m每50m都有一件事情要做。为了测试,我将所有这些位置存储在一个数组中。我们的测试用户有一个按钮,可以将GPX格式的历史记录通过邮件发送给我。


例如以下12个发送给我的位置:

 <?xml version = 1.0 encoding = UTF-8? 
< gpx xmlns = http://www.topografix.com/GPX/1/1版本= 1.1 creator = flitsmeister-ios-app-test xmlns:xsi = http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation = http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd
< wpt lat = 51.28165091 lon = 5.77329012
< datetimegps> 2015-09-29T04:36:55.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:55.460< / datetimeprocessed>
< course> 61.5< / course>
< speed> 13.3< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.1< / altitude>
< sequencenr> 0< / sequencenr>
< / wpt>
< wpt lat =" 51.28138654" lon = 5.77244497。
< datetimegps> 2015-09-29T04:36:55.506< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:55.523< / datetimeprocessed>
< course> 69.3< / course>
< speed> 13.5< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.7< / altitude>
< sequencenr> 1< / sequencenr>
< / wpt>
< wpt lat = 51.28171319; lon = 5.77345935
< datetimegps> 2015-09-29T04:36:56.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:56.441< / datetimeprocessed>
< course> 61.2< / course>
< speed> 13.2< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.0< / altitude>
< sequencenr> 2< / sequencenr>
< / wpt>
< wpt lat =" 51.28138654" lon = 5.77244497。
< datetimegps> 2015-09-29T04:36:56.562< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:56.571< / datetimeprocessed>
< course> 69.3< / course>
< speed> 13.5< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.7< / altitude>
< sequencenr> 3< / sequencenr>
< / wpt>
< wpt lat = 51.28177064 lon = 5.77362548。
< datetimegps> 2015-09-29T04:36:57.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:57.440< / datetimeprocessed>
< course> 60.1< / course>
< speed> 13.4< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 32.9< / altitude>
< sequencenr> 4< / sequencenr>
< / wpt>
< wpt lat =" 51.28138654" lon = 5.77244497。
< datetimegps> 2015-09-29T04:36:57.541< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:57.558< / datetimeprocessed>
< course> 69.3< / course>
< speed> 13.5< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.7< / altitude>
< sequencenr> 5< / sequencenr>
< / wpt>
< wpt lat = 51.28182383 lon = 5.77380183
< datetimegps> 2015-09-29T04:36:58.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:58.438< / datetimeprocessed>
< course> 61.2< / course>
< speed> 13.7< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.3< / altitude>
< sequencenr> 6< / sequencenr>
< / wpt>
< wpt lat =" 51.28138654" lon = 5.77244497。
< datetimegps> 2015-09-29T04:36:58.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:58.491< / datetimeprocessed>
< course> 69.3< / course>
< speed> 13.5< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.7< / altitude>
< sequencenr> 7< / sequencenr>
< / wpt>
< wpt lat = 51.28188803 lon = 5.77398322。
< datetimegps> 2015-09-29T04:36:59.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:36:59.431< / datetimeprocessed>
< course> 61.5< / course>
< speed> 14.4< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.4< / altitude>
< sequencenr> 8< / sequencenr>
< / wpt>
< wpt lat =" 51.28202386" lon = 5.77435235
< datetimegps> 2015-09-29T04:37:01.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:37:01.432< / datetimeprocessed>
< course> 61.2< / course>
< speed> 14.9< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.5< / altitude>
< sequencenr> 9< / sequencenr>
< / wpt>
< wpt lat = 51.28188803 lon = 5.77398322。
< datetimegps> 2015-09-29T04:37:01.444< / datetimegps>
< datetimeprocessed> 2015-09-29T04:37:01.454< / datetimeprocessed>
< course> 61.5< / course>
< speed> 14.4< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.4< / altitude>
< sequencenr> 10< / sequencenr>
< / wpt>
< wpt lat = 51.28208027 lon = 5.77454128
< datetimegps> 2015-09-29T04:37:02.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:37:02.430< / datetimeprocessed>
< course> 61.9< / course>
< speed> 15.1< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.3< / altitude>
< sequencenr> 11< / sequencenr>
< / wpt>
< wpt lat = 51.28188803 lon = 5.77398322。
< datetimegps> 2015-09-29T04:37:02.513< / datetimegps>
< datetimeprocessed> 2015-09-29T04:37:02.521< / datetimeprocessed>
< course> 61.5< / course>
< speed> 14.4< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.4< / altitude>
< sequencenr> 12< / sequencenr>
< / wpt>
< wpt lat = 51.28217918 lon = 5.77472677。
< datetimegps> 2015-09-29T04:37:03.371< / datetimegps>
< datetimeprocessed> 2015-09-29T04:37:03.434< / datetimeprocessed>
< course> 61.5< / course>
< speed> 15.2< / speed>
< accuracyhorizo​​ntal> 5.0< / accuracyhorizo​​ntal>
< accuracyvertical> 3.0< / accuracyvertical>
< altitude> 33.5< / altitude>
< sequencenr> 13< / sequencenr>
< / wpt>
< / gpx>

如果我在地图上打印这些位置(geoplaner.com是我的朋友),我将看到以下内容:



备注:点BDFH位于相同位置,但仅用于说明问题


如您所见,如果遵循序列A,B,C,您将看到B点不在正确的位置。 / p>

从iOS9开始,几乎每个测试用户一周都会遇到这种情况一两次。


下面我们使用一些代码:


CLLocationManager(在平均线程上):

  _manager = [[CLLocationManager alloc] init]; 
_manager.delegate =自我;
_manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_manager.activityType = CLActivityTypeAutomotiveNavigation;
_manager.pausesLocationUpdatesAutomatically = TRUE;

if([_ manager responsesToSelector:@selector(allowsBackgroundLocationUpdates)])
_manager.allowsBackgroundLocationUpdates = TRUE;
[_manager requestAlwaysAuthorization];

在另一种方法中,我称为start(也可以在应用启动时调用,在应用终止时停止)。 (主线程)

  [_ manager startUpdatingLocation]; 

使用位置信息的代码(我删除了一些代码以保持示例简洁):

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{
CLLocation * lastLocation = [locations lastObject];

//测试如果(lastLocation.horizo​​ntalAccuracy< 0)
返回,则水平精度不表示无效的测量


//测试位置测量的时间以确定是否缓存了测量
//在大多数情况下,您将不希望依赖已缓存的测量
NSTimeInterval locationAge =- [lastLocation.timestamp timeIntervalSinceNow];
如果(locationAge> 5.0)
返回;

NSDate * dateLocationArrived = [NSDate date];

CLLocation * beforeLocationRealtime = [self.LastLocationRealtime副本];
CLLocation * newLocation = [lastLocation复制];


//实时位置。
[self setSpeedForLocation:[newLocation copy] withOldRealtimeLocation:[beforeLocationRealtime copy]];

[_delegateKaart UpdatedRealtimeLocation:newLocation fromPreviousLocation:[self.PreviousCurrentLocation copy]];

self.BeforeLastLocationRealtime = [self.LastLocationRealtime副本];
self.LastLocationRealtime = [newLocation副本];

if([self.CurrentLocation distanceFromLocation:newLocation]< 50)//少于50m?
{
if([__ Each25m distanceFromLocation:newLocation]> 25)
{
// Nieuwe最后25m。
_locationEach25m = [newLocation副本];


//每25m做
[_delegateDashboard UpdatedLocation:[newLocation copy]];
[_delegateSignalering locationUpdated:[newLocation copy]];

[self holdLast200LocationsAndAddLocation:[lastLocation copy] withLocationArray:locations AndArriveDate:dateLocationArrived AndVerwerkt:TRUE];
}
else
[self holdLast200LocationsAndAddLocation:[lastLocation copy] withLocationArray:locations AndArriveDate:dateLocationArrived AndVerwerkt:FALSE];
return; //停止
}

//每50m
[self holdLast200LocationsAndAddLocation:[lastLocation copy] withLocationArray:locations AndArriveDate:dateLocationArrived AndVerwerkt:TRUE];

_locationEach25m = [newLocation副本]; //最新的最后25m。
self.PreviousCurrentLocation = [self.CurrentLocation复制]; // 50m返回。
self.CurrentLocation = [newLocation复制];

[_delegateDashboard UpdatedLocation:[newLocation复制]];
[_delegateSignalering locationUpdated:[newLocation copy]];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^ {
[_delegateCountryDetector locationUpdated:[newLocation copy]];
[self setHuidigeWegForLocation:[newLocation copy]];
});

[[SignaleringController sharedInstance] runSignaleringCheckForLocation:[newLocation复制]];
}


感觉就像locationmanager中的iOS9错误我对用户的下落有不正确的结果。如果我搜索Stackoverflow.com,似乎我是唯一的一个。


->范例2:


 < wpt lat =" 52.32835728" lon = 5.05861943。 
< datetimegps> 2015-10-01T06:27:29.905< / datetimegps>
< datetimearrivedincode> 2015-10-01T06:27:30.196< / datetimearrivedincode>
< datetimeprocessed> 2015-10-01T06:27:30.205< / datetimeprocessed>
< c> 138.4< / c>
< s> 26.5< / s>
< accuracyhorizo​​ntal> 1.0< / accuracyhorizo​​ntal>
< accuracyvertical> 6.0< / accuracyvertical>
< al> 5.9< / al>
< nr> 95< / nr>
< / wpt>
< wpt lat =" 52.32813366" lon = 5.05927501。
< datetimegps> 2015-10-01T06:27:31.905< / datetimegps>
< datetimearrivedincode> 2015-10-01T06:27:32.275< / datetimearrivedincode>
< datetimeprocessed> 2015-10-01T06:27:32.301< / datetimeprocessed>
< c> 119.5< / c>
< s> s 26.0< / s>
< accuracyhorizo​​ntal> 1.0< / accuracyhorizo​​ntal>
< accuracyvertical> 4.0< / accuracyvertical>
< al> 5.7< / al>
< nr> 96< / nr>
< / wpt>
< wpt lat =" 52.32835728" lon = 5.05861943。
< datetimegps> 2015-10-01T06:27:33.196< / datetimegps>
< datetimearrivedincode> 2015-10-01T06:27:33.203< / datetimearrivedincode>
< datetimeprocessed> 2015-10-01T06:27:33.275< / datetimeprocessed>
< c> 138.4< / c>
< s> 26.5< / s>
< accuracyhorizo​​ntal> 1.0< / accuracyhorizo​​ntal>
< accuracyvertical> 6.0< / accuracyvertical>
< al> 5.9< / al>
< nr> 97< / nr>
< / wpt>
< wpt lat = 52.32802075 lon = 5.05960610&。
< datetimegps> 2015-10-01T06:27:32.905< / datetimegps>
< datetimearrivedincode> 2015-10-01T06:27:33.246< / datetimearrivedincode>
< datetimeprocessed> 2015-10-01T06:27:33.283< / datetimeprocessed>
< c> 119.2< / c>
< s> 26.3< / s>
< accuracyhorizo​​ntal> 1.0< / accuracyhorizo​​ntal>
< accuracyvertical> 4.0< / accuracyvertical>
< al> 5.3< / al>
< nr> 98< / nr>
< / wpt>

在地图上:



注意:A和C在确切的位置,我手动更改它们以显示A在C的后面。


以下内容很奇怪:


  1. 4rd / D的GPS时间更早,然后指向3rd / C

  2. 不知为何我没有找到06的位置: 27:31,但得到两个06:27:33

  3. 第一和第三位和第三位具有相同的GPS坐标。这是不正确的,因为汽车以26m / s(93km / h)的速度行驶在高速公路上。

第3点表示我不能通过以下方式解决问题:


->示例3:


GPX文件总数:


将重复的和错误的订单点彼此相邻移动:


只需重新加载我对ABCD表示法感兴趣的点即可。


上述屏幕截图中的GPX文件:

 <?xml version = 1.0 encoding = UTF-8? 
< gpx xmlns = http://www.topografix.com/GPX/1/1版本= 1.1 creator = flitsmeister-ios-app-test xmlns:xsi = http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation = http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd
< wpt lat = 51.89792674 lon = 4.54830456
< tgps> 2015-09-29T15:23:40.999< / tgps>
< tv> 2015-09-29T15:23:53.850< / tv>
< c> 131.8< / c>
< s> 13.1< / s>
< ah> 5.0< / ah>
< av> 3.0< / av>
< al> 2.0< / al>
< nr> 464< / nr>
< / wpt>
< wpt lat = 51.89745789 lon = 4.54927853。
< tgps> 2015-09-29T15:23:47.999< / tgps>
< tv> 2015-09-29T15:23:53.910< / tv>
< c> 125.9< / c>
< s> 8.6< / s>
< ah> 5.0< / ah>
< av> 6.0< / av>
< al> 5.4< / al>
< nr> 465< / nr>
< / wpt>
< wpt lat = 51.89745789 lon = 4.54927853。
< tgps> 2015-09-29T15:23:47.999< / tgps>
< tv> 2015-09-29T15:23:53.929< / tv>
< c> 125.9< / c>
< s> 8.6< / s>
< ah> 5.0< / ah>
< av> 6.0< / av>
< al> 5.4< / al>
< nr> 466< / nr>
< / wpt>
< wpt lat = 51.89745789 lon = 4.54927853。
< tgps> 2015-09-29T15:23:47.999< / tgps>
< tv> 2015-09-29T15:23:53.932< / tv>
< c> 125.9< / c>
< s> 8.6< / s>
< ah> 5.0< / ah>
< av> 6.0< / av>
< al> 5.4< / al>
< nr> 467< / nr>
< / wpt>
< wpt lat = 51.89762654 lon = 4.54890185。
< tgps> 2015-09-29T15:23:44.999< / tgps>
< tv> 2015-09-29T15:23:53.933< / tv>
< c> 128.0< / c>
< s> 13.4< / s>
< ah> 5.0< / ah>
< av> 4.0< / av>
< al> 0.6 // al
< nr> 468< / nr>
< / wpt>
< wpt lat = 51.89745789 lon = 4.54927853。
< tgps> 2015-09-29T15:23:47.999< / tgps>
< tv> 2015-09-29T15:23:53.965< / tv>
< c> 125.9< / c>
< s> 8.6< / s>
< ah> 5.0< / ah>
< av> 6.0< / av>
< al> 5.4< / al>
< nr> 469< / nr>
< / wpt>
< wpt lat = 51.89755810 lon = 4.54904694。
< tgps> 2015-09-29T15:23:45.999< / tgps>
< tv> 2015-09-29T15:24:02.016< / tv>
< c> 126.9< / c>
< s> 12.5< / s>
< ah> 5.0< / ah>
< av> 4.0< / av>
< al> 0.2< / al
< nr> 470< / nr>
< / wpt>
< wpt lat = 51.89800163 lon = 4.54815385
< tgps> 2015-09-29T15:23:47.731< / tgps>
< tv> 2015-09-29T15:24:02.068< / tv>
< c> 132.9< / c>
< s> 12.8< / s>
< ah> 5.0< / ah>
< av> 4.0< / av>
< al> 2.3< / al>
< nr> 471< / nr>
< / wpt>
< wpt lat = 51.89800163 lon = 4.54815385
< tgps> 2015-09-29T15:23:47.999< / tgps>
< tv> 2015-09-29T15:24:05.832< / tv>
< c> 132.9< / c>
< s> 12.8< / s>
< ah> 5.0< / ah>
< av> 4.0< / av>
< al> 2.3< / al>
< nr> 472< / nr>
< / wpt>
< wpt lat =" 51.89749909" lon = 4.54917803。
< tgps> 2015-09-29T15:23:46.999< / tgps>
< tv> 2015-09-29T15:24:05.842< / tv>
< c> 126.9< / c>
< s> 10.8< / s>
< ah> 5.0< / ah>
< av> 4.0< / av>
< al> 8.4< / al>
< nr> 473< / nr>
< / wpt>
< wpt lat = 51.89800163 lon = 4.54815385
< tgps> 2015-09-29T15:23:47.999< / tgps>
< tv> 2015-09-29T15:24:06.289< / tv>
< c> 132.9< / c>
< s> 12.8< / s>
< ah> 5.0< / ah>
< av> 4.0< / av>
< al> 2.3< / al>
< nr> 474< / nr>
< / wpt>
< wpt lat = 51.89745789 lon = 4.54927853。
< tgps> 2015-09-29T15:23:47.999< / tgps>
< tv> 2015-09-29T15:24:06.307< / tv>
< c> 125.9< / c>
< s> 8.6< / s>
< ah> 5.0< / ah>
< av> 6.0< / av>
< al> 5.4< / al>
< nr> 475< / nr>
< / wpt>
< wpt lat =" 51.89732735" lon = 4.54958171>
< tgps> 2015-09-29T15:23:52.999< / tgps>
< tv> 2015-09-29T15:24:06.339< / tv>
< c> 121.6< / c>
< s> 2.9< / s>
< ah> 5.0< / ah>
< av> 4.0< / av>
al -2.3 / al
< nr> 476< / nr>
< / wpt>
< / gpx>

在此文件中,该问题发生了几次,但似乎位于2个问题位置。之后,再也没有问题了,但是用户在经过KM之后就终止了该应用程序。


->我尝试过:



  1. 将ActivityType设置为CLActivityTypeAutomotiveNavigation

  2. 将pauseLocationLocationsAutosAuto设置为YES

  3. 将所需精度设置为kCLLocationAccuracyBestForNavigation

  4. 将所有内容移至主线程,并且不进行任何线程更改。

  5. 扩展日志记录以查看是否数组位置包含一个以上的location对象,但事实并非如此。

  6. 记录HASH和Pointer位置,但它们都不同。


->我了解到:



  1. 不要将pausesLocationUpdates自动设置为FALSE。默认值为TRUE,对于导航应用,应保持为TRUE。将其设置为FALSE时,您将获得更多的位置,这些位置与另一个位置没有什么不同。



  2. 在CLLocationManager上设置属性一次,当您将属性更改为通常很奇怪时,就会有更多的位置到达委托人。例如:如果在委托方法didUpdateLocation中设置这些属性,则最终将在完全相同的毫秒数上得到4个位置。


    _manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
    _manager.activityType = CLActivityTypeAutomotiveNavigation;




解决方案

我终于明白了。以下是错误的地方:


  1. 我的项目中每秒都有另一个CLLocationManager运行此代码:



    [locationManager startUpdatingLocation];
    if([[locationManager responsesToSelector:@selector(allowsBackgroundLocationUpdates)])){
    locationManager.allowsBackgroundLocationUpdates = TRUE;
    }


  2. 我多次在CLLocationManager上设置属性。当您过于频繁地更改属性时,奇怪而多余的位置将到达委托。例如:如果在委托方法 didUpdateLocation 中设置这些属性,则最终将在完全相同的毫秒数上得到4个位置。



    _manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;

    _manager.activityType = CLActivityTypeAutomotiveNavigation;


  3. 我们发现有一个测试用户他的GPS芯片坏了。由于某种原因,他的设备偶尔会报告错误的GPS坐标。确保至少有两个用户报告错误!在固定点1和2的某个时刻,该用户有此错误,但其他所有用户都可以。后来他还报告了商店版本(使用iOS8构建)的错误。


  4. 不要自动禁用 pausesLocationUpdates (将其设置为false)。它默认为启用,对于导航应用程序,应保持启用状态。禁用此功能后,您将获得更多的位置,这些位置与另一个位置没有什么不同。


所以是的,iOS8和iOS9之间有很大差异。如果您遇到奇怪的地点,请在上面检查这些要点。


We experience some weird issues on the locations from CCLocationManager starting from iOS9. iOS 7-8 has no issues. The weird locations cause errors in the app. The app is used while driving a car and we have about 50 test users in TestFlight and some of them are reporting these issues.

The app reacts on location updates, each location update, each 25m and each 50m there is something to do. For test I've stored all these locations in an array. Our test users have a button which will send the history in GPX format to me by mail.

For example the following 12 locations where send to me:

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="flitsmeister-ios-app-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
  <wpt lat="51.28165091" lon="5.77329012">
    <datetimegps>2015-09-29T04:36:55.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:55.460</datetimeprocessed>
    <course>61.5</course>
    <speed>13.3</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.1</altitude>
    <sequencenr>0</sequencenr>
  </wpt>
  <wpt lat="51.28138654" lon="5.77244497">
    <datetimegps>2015-09-29T04:36:55.506</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:55.523</datetimeprocessed>
    <course>69.3</course>
    <speed>13.5</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.7</altitude>
    <sequencenr>1</sequencenr>
  </wpt>
  <wpt lat="51.28171319" lon="5.77345935">
    <datetimegps>2015-09-29T04:36:56.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:56.441</datetimeprocessed>
    <course>61.2</course>
    <speed>13.2</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.0</altitude>
    <sequencenr>2</sequencenr>
  </wpt>
  <wpt lat="51.28138654" lon="5.77244497">
    <datetimegps>2015-09-29T04:36:56.562</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:56.571</datetimeprocessed>
    <course>69.3</course>
    <speed>13.5</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.7</altitude>
    <sequencenr>3</sequencenr>
  </wpt>
  <wpt lat="51.28177064" lon="5.77362548">
    <datetimegps>2015-09-29T04:36:57.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:57.440</datetimeprocessed>
    <course>60.1</course>
    <speed>13.4</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>32.9</altitude>
    <sequencenr>4</sequencenr>
  </wpt>
  <wpt lat="51.28138654" lon="5.77244497">
    <datetimegps>2015-09-29T04:36:57.541</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:57.558</datetimeprocessed>
    <course>69.3</course>
    <speed>13.5</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.7</altitude>
    <sequencenr>5</sequencenr>
  </wpt>
  <wpt lat="51.28182383" lon="5.77380183">
    <datetimegps>2015-09-29T04:36:58.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:58.438</datetimeprocessed>
    <course>61.2</course>
    <speed>13.7</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.3</altitude>
    <sequencenr>6</sequencenr>
  </wpt>
  <wpt lat="51.28138654" lon="5.77244497">
    <datetimegps>2015-09-29T04:36:58.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:58.491</datetimeprocessed>
    <course>69.3</course>
    <speed>13.5</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.7</altitude>
    <sequencenr>7</sequencenr>
  </wpt>
  <wpt lat="51.28188803" lon="5.77398322">
    <datetimegps>2015-09-29T04:36:59.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:36:59.431</datetimeprocessed>
    <course>61.5</course>
    <speed>14.4</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.4</altitude>
    <sequencenr>8</sequencenr>
  </wpt>
  <wpt lat="51.28202386" lon="5.77435235">
    <datetimegps>2015-09-29T04:37:01.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:37:01.432</datetimeprocessed>
    <course>61.2</course>
    <speed>14.9</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.5</altitude>
    <sequencenr>9</sequencenr>
  </wpt>
  <wpt lat="51.28188803" lon="5.77398322">
    <datetimegps>2015-09-29T04:37:01.444</datetimegps>
    <datetimeprocessed>2015-09-29T04:37:01.454</datetimeprocessed>
    <course>61.5</course>
    <speed>14.4</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.4</altitude>
    <sequencenr>10</sequencenr>
  </wpt>
  <wpt lat="51.28208027" lon="5.77454128">
    <datetimegps>2015-09-29T04:37:02.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:37:02.430</datetimeprocessed>
    <course>61.9</course>
    <speed>15.1</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.3</altitude>
    <sequencenr>11</sequencenr>
  </wpt>
  <wpt lat="51.28188803" lon="5.77398322">
    <datetimegps>2015-09-29T04:37:02.513</datetimegps>
    <datetimeprocessed>2015-09-29T04:37:02.521</datetimeprocessed>
    <course>61.5</course>
    <speed>14.4</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.4</altitude>
    <sequencenr>12</sequencenr>
  </wpt>
  <wpt lat="51.28217918" lon="5.77472677">
    <datetimegps>2015-09-29T04:37:03.371</datetimegps>
    <datetimeprocessed>2015-09-29T04:37:03.434</datetimeprocessed>
    <course>61.5</course>
    <speed>15.2</speed>
    <accuracyhorizontal>5.0</accuracyhorizontal>
    <accuracyvertical>3.0</accuracyvertical>
    <altitude>33.5</altitude>
    <sequencenr>13</sequencenr>
  </wpt>
</gpx>

If I print these location on a map (geoplaner.com is my friend), I will see this:

Remark: Points B D F H are on the same location, but for the illustration of the problem I have put those on 1 row next to each other.

As you can see if you follow the sequence A,B,C you will see that point B is not on the right location.

Starting from iOS9 build almost every test user has experienced this situation once or two times in a week.

Following some code we use:

CLLocationManager (on the mean thread):

_manager = [[CLLocationManager alloc] init];
_manager.delegate = self;
_manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_manager.activityType = CLActivityTypeAutomotiveNavigation;
_manager.pausesLocationUpdatesAutomatically = TRUE;

if([_manager respondsToSelector:@selector(allowsBackgroundLocationUpdates)])
    _manager.allowsBackgroundLocationUpdates = TRUE;
[_manager requestAlwaysAuthorization];

In another method I call the start (also when app starts and stop it when it terminates). (main thread)

[_manager startUpdatingLocation];

Code for working with Locations (I've removed some code to keep the example clean):

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *lastLocation = [locations lastObject];

    // test that the horizontal accuracy does not indicate an invalid measurement
    if (lastLocation.horizontalAccuracy < 0)
        return;
    
    // test the age of the location measurement to determine if the measurement is cached
    // in most cases you will not want to rely on cached measurements
    NSTimeInterval locationAge = -[lastLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0)
        return;

    NSDate *dateLocationArrived = [NSDate date];
    
    CLLocation *beforeLocationRealtime = [self.LastLocationRealtime copy];
    CLLocation *newLocation = [lastLocation copy];


    //Realtime location.
    [self setSpeedForLocation:[newLocation copy] withOldRealtimeLocation:[beforeLocationRealtime copy]];
    
    [_delegateKaart updatedRealtimeLocation:newLocation fromPreviousLocation:[self.PreviousCurrentLocation copy]];
    
    self.BeforeLastLocationRealtime = [self.LastLocationRealtime copy];
    self.LastLocationRealtime = [newLocation copy];

    if([self.CurrentLocation distanceFromLocation:newLocation] < 50) //Less then 50m?
    {
        if([_locationEach25m distanceFromLocation:newLocation] > 25)
        {
            //Nieuwe last 25m.
            _locationEach25m = [newLocation copy];
            
   
            //Each 25m do
            [_delegateDashboard updatedLocation:[newLocation copy]];
            [_delegateSignalering locationUpdated:[newLocation copy]];
            
            [self holdLast200LocationsAndAddLocation:[lastLocation copy] withLocationArray:locations AndArriveDate:dateLocationArrived AndVerwerkt:TRUE];
        }
        else
            [self holdLast200LocationsAndAddLocation:[lastLocation copy] withLocationArray:locations AndArriveDate:dateLocationArrived AndVerwerkt:FALSE];
        return;//Stop
    }

    //Each 50m 
    [self holdLast200LocationsAndAddLocation:[lastLocation copy] withLocationArray:locations AndArriveDate:dateLocationArrived AndVerwerkt:TRUE];

    _locationEach25m = [newLocation copy]; //Also new last 25m .
    self.PreviousCurrentLocation = [self.CurrentLocation copy];//50m back. 
    self.CurrentLocation = [newLocation copy]; 
    
    [_delegateDashboard updatedLocation:[newLocation copy]];
    [_delegateSignalering locationUpdated:[newLocation copy]];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [_delegateCountryDetector locationUpdated:[newLocation copy]];
        [self setHuidigeWegForLocation:[newLocation copy]];
    });
    
    [[SignaleringController sharedInstance] runSignaleringCheckForLocation:[newLocation copy]];
}

 

It feels like an iOS9 bug in the locationmanager which is giving me incorrect results on the whereabouts of the user. If I search Stackoverflow.com it seems Im the only one.

--> Example2:

  <wpt lat="52.32835728" lon="5.05861943">
    <datetimegps>2015-10-01T06:27:29.905</datetimegps>
    <datetimearrivedincode>2015-10-01T06:27:30.196</datetimearrivedincode>
    <datetimeprocessed>2015-10-01T06:27:30.205</datetimeprocessed>
    <c>138.4</c>
    <s>26.5</s>
    <accuracyhorizontal>10.0</accuracyhorizontal>
    <accuracyvertical>6.0</accuracyvertical>
    <al>5.9</al>
    <nr>95</nr>
  </wpt>
  <wpt lat="52.32813366" lon="5.05927501">
    <datetimegps>2015-10-01T06:27:31.905</datetimegps>
    <datetimearrivedincode>2015-10-01T06:27:32.275</datetimearrivedincode>
    <datetimeprocessed>2015-10-01T06:27:32.301</datetimeprocessed>
    <c>119.5</c>
    <s>26.0</s>
    <accuracyhorizontal>10.0</accuracyhorizontal>
    <accuracyvertical>4.0</accuracyvertical>
    <al>5.7</al>
    <nr>96</nr>
  </wpt>
  <wpt lat="52.32835728" lon="5.05861943">
    <datetimegps>2015-10-01T06:27:33.196</datetimegps>
    <datetimearrivedincode>2015-10-01T06:27:33.203</datetimearrivedincode>
    <datetimeprocessed>2015-10-01T06:27:33.275</datetimeprocessed>
    <c>138.4</c>
    <s>26.5</s>
    <accuracyhorizontal>10.0</accuracyhorizontal>
    <accuracyvertical>6.0</accuracyvertical>
    <al>5.9</al>
    <nr>97</nr>
  </wpt>
  <wpt lat="52.32802075" lon="5.05960610">
    <datetimegps>2015-10-01T06:27:32.905</datetimegps>
    <datetimearrivedincode>2015-10-01T06:27:33.246</datetimearrivedincode>
    <datetimeprocessed>2015-10-01T06:27:33.283</datetimeprocessed>
    <c>119.2</c>
    <s>26.3</s>
    <accuracyhorizontal>10.0</accuracyhorizontal>
    <accuracyvertical>4.0</accuracyvertical>
    <al>5.3</al>
    <nr>98</nr>
  </wpt>

On the map:

Note: A and C are on the exact location, I changed them manually to show A is behind C.

The following is weird:

  1. 4rd/D has an earlier GPS time then point 3rd/C
  2. Somehow I didnt get a location for 06:27:31 but got two 06:27:33
  3. 1st/A and 3rd/C have the same GPS coordinates. This can't be correct because the car is driving the highway 26m/s (93km/h).

Point 3 means I cant just fix it by holding the last GPS date and skip everything earlier then the last one.

--> Example 3:

Total GPX file:

Zoomed-in at the problem:

Moved the double and incorrect order points next to each other:

Just reloaded the points im interested in with ABCD notations.

The GPX file from the above screenshot:

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="flitsmeister-ios-app-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<wpt lat="51.89792674" lon="4.54830456">
  <tgps>2015-09-29T15:23:40.999</tgps>
  <tv>2015-09-29T15:23:53.850</tv>
  <c>131.8</c>
  <s>13.1</s>
  <ah>5.0</ah>
  <av>3.0</av>
  <al>2.0</al>
  <nr>464</nr>
</wpt>
<wpt lat="51.89745789" lon="4.54927853">
  <tgps>2015-09-29T15:23:47.999</tgps>
  <tv>2015-09-29T15:23:53.910</tv>
  <c>125.9</c>
  <s>8.6</s>
  <ah>5.0</ah>
  <av>6.0</av>
  <al>5.4</al>
  <nr>465</nr>
</wpt>
<wpt lat="51.89745789" lon="4.54927853">
  <tgps>2015-09-29T15:23:47.999</tgps>
  <tv>2015-09-29T15:23:53.929</tv>
  <c>125.9</c>
  <s>8.6</s>
  <ah>5.0</ah>
  <av>6.0</av>
  <al>5.4</al>
  <nr>466</nr>
</wpt>
<wpt lat="51.89745789" lon="4.54927853">
  <tgps>2015-09-29T15:23:47.999</tgps>
  <tv>2015-09-29T15:23:53.932</tv>
  <c>125.9</c>
  <s>8.6</s>
  <ah>5.0</ah>
  <av>6.0</av>
  <al>5.4</al>
  <nr>467</nr>
</wpt>
<wpt lat="51.89762654" lon="4.54890185">
  <tgps>2015-09-29T15:23:44.999</tgps>
  <tv>2015-09-29T15:23:53.933</tv>
  <c>128.0</c>
  <s>13.4</s>
  <ah>5.0</ah>
  <av>4.0</av>
  <al>0.6</al>
  <nr>468</nr>
</wpt>
<wpt lat="51.89745789" lon="4.54927853">
  <tgps>2015-09-29T15:23:47.999</tgps>
  <tv>2015-09-29T15:23:53.965</tv>
  <c>125.9</c>
  <s>8.6</s>
  <ah>5.0</ah>
  <av>6.0</av>
  <al>5.4</al>
  <nr>469</nr>
</wpt>
<wpt lat="51.89755810" lon="4.54904694">
  <tgps>2015-09-29T15:23:45.999</tgps>
  <tv>2015-09-29T15:24:02.016</tv>
  <c>126.9</c>
  <s>12.5</s>
  <ah>5.0</ah>
  <av>4.0</av>
  <al>0.2</al>
  <nr>470</nr>
</wpt>
<wpt lat="51.89800163" lon="4.54815385">
  <tgps>2015-09-29T15:23:47.731</tgps>
  <tv>2015-09-29T15:24:02.068</tv>
  <c>132.9</c>
  <s>12.8</s>
  <ah>5.0</ah>
  <av>4.0</av>
  <al>2.3</al>
  <nr>471</nr>
</wpt>
<wpt lat="51.89800163" lon="4.54815385">
  <tgps>2015-09-29T15:23:47.999</tgps>
  <tv>2015-09-29T15:24:05.832</tv>
  <c>132.9</c>
  <s>12.8</s>
  <ah>5.0</ah>
  <av>4.0</av>
  <al>2.3</al>
  <nr>472</nr>
</wpt>
<wpt lat="51.89749909" lon="4.54917803">
  <tgps>2015-09-29T15:23:46.999</tgps>
  <tv>2015-09-29T15:24:05.842</tv>
  <c>126.9</c>
  <s>10.8</s>
  <ah>5.0</ah>
  <av>4.0</av>
  <al>8.4</al>
  <nr>473</nr>
</wpt>
<wpt lat="51.89800163" lon="4.54815385">
  <tgps>2015-09-29T15:23:47.999</tgps>
  <tv>2015-09-29T15:24:06.289</tv>
  <c>132.9</c>
  <s>12.8</s>
  <ah>5.0</ah>
  <av>4.0</av>
  <al>2.3</al>
  <nr>474</nr>
</wpt>
<wpt lat="51.89745789" lon="4.54927853">
  <tgps>2015-09-29T15:23:47.999</tgps>
  <tv>2015-09-29T15:24:06.307</tv>
  <c>125.9</c>
  <s>8.6</s>
  <ah>5.0</ah>
  <av>6.0</av>
  <al>5.4</al>
  <nr>475</nr>
</wpt>
<wpt lat="51.89732735" lon="4.54958171">
  <tgps>2015-09-29T15:23:52.999</tgps>
  <tv>2015-09-29T15:24:06.339</tv>
  <c>121.6</c>
  <s>2.9</s>
  <ah>5.0</ah>
  <av>4.0</av>
  <al>-2.3</al>
  <nr>476</nr>
</wpt>
  </gpx>

In this file the problem occurred a couple times but seems to locate at 2 problem locations. After that no problems more but the user killed the app after a some KM.

--> I've tried:

  1. Setting ActivityType to CLActivityTypeAutomotiveNavigation
  2. Setting pauseLocationUpdatesAuto to YES
  3. DesiredAccuracy to kCLLocationAccuracyBestForNavigation
  4. Moving everything to the main thread and don't do any thread changing.
  5. Extending the logging to see if my array Locations contains more then one locationobject, but this isn't the case.
  6. Logging the HASH and Pointer location, but they are all differently.

--> I've learned:

  1. Don't set pausesLocationUpdatesAutomatically to FALSE. It's default TRUE and for a navigation app it should stay TRUE. You will get a lot more locations when you set this to FALSE, locations that are no different to another one.

  2. Set properties on the CLLocationManager once, when you change properties to often weird and more locations will arrive at the delegate. In example: if you set these properties in the delegate method didUpdateLocation you will end up with 4 locations on the exact same millisecond.

    _manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; _manager.activityType = CLActivityTypeAutomotiveNavigation;

解决方案

I finally figured it out. The following things where wrong:

  1. I had another CLLocationManager in my project running this code each second:

    [locationManager startUpdatingLocation]; if([locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]) { locationManager.allowsBackgroundLocationUpdates = TRUE; }

  2. I was setting properties on the CLLocationManager more than once. When you change properties too often, weird and extra locations will arrive at the delegate. For example: if you set these properties in the delegate method didUpdateLocation you will end up with 4 locations on the exact same millisecond.

    _manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
    _manager.activityType = CLActivityTypeAutomotiveNavigation;

  3. We have found out that one test user had his GPS chip broken or something. For some reason his device reported wrong GPS coordinates occasionally. Make sure at least two users are reporting an error! At some point when we fixed point 1 and 2, this user had this error but all other users were OK. Later on he also reported errors with the store version (which was build with iOS8).

  4. Don't disable pausesLocationUpdatesAutomatically (set it to false). It defaults to enabled and for a navigation app it should stay enabled. You will get a lot more locations when you disable this, locations that are no different to another one.

So yes, there is a big difference between iOS8 and iOS9. If you experience weird locations check these points above.

这篇关于iOS9中的CLLocationManager提供错误的位置(iOS8正常)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆