iOS Core Location - Get MOST Accurate Location Coordinates

自闭症网瘾萝莉.ら 提交于 2019-12-23 23:51:35

问题


On an app I am working on I need to track the a user's journey, and then map it to the user. In this scenario I need the most accurate location data possible.

I have created a CLLocationManager for this task. In order to revive the most accurate location possible I set the desired accuracy filter of the manager to kCLLocationAccuracyBest. In order to ensure I don't get extra coordinates when the user is not moving, I set the distance filter the manager to 2.5 meters.

However, I was still felt like I would probably get some inaccurate coordinates, so in my -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations delegate method, I set up a filter that uses the estimated horizontal and vertical accuracy of each coordinate to determine whether or not it should be kept or not, and if the coordinate meets the criteria it is stored an an array.

Here is my implementation:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
    for (CLLocation *loc in locations) {
         if (loc.horizontalAccuracy > -1 && loc.horizontalAccuracy <= 10 && loc.verticalAccuracy > -1 && loc.verticalAccuracy <= 30){
         [self.locationArray addObject:loc];
    }
}

Most of the time, this works pretty well. Requiring a horizontal accuracy of 10 meters and a vertical accuracy of 30 meters seems to be about the best location information the location manager can give me consistently. It ensures the coordinates are an accurate representation of the user's journey. However, in my testing, sometimes the location manager is unable to meet this criteria. This results in a large gap between coordinate points.

A possible solution to this problem would be to loosen the criteria of my filter. However this is problematic because it would result in my keeping inaccurate points when more accurate ones are available.

Another possible solution would be to collect locations for an interval (ex. 30 seconds), then go through them and find the best one. However the problem with this is that in my app the user will probably be moving, possibly at high speeds. The user's location could change significantly in 30 seconds.

I feel like there is a more elegant way to ensure that the coordinates saved have the best accuracy available, but my knowledge of Core Location is limited and I can't seem to find a better solution.

What would be the best way to solve this problem?


回答1:


You're going to need to come up with custom logic. You're going to need to juggle accuracy, elapsed time, and distance traveled per unit time (average speed between readings.)

Maybe save ALL your location readings in memory until you decide what to do with them. If a 30-second batch of readings doesn't have much of a change in distance (and the change in distance is less than accuracy reading) then take the best reading from that 30 seconds. If the position is changing rapidly, however, you might need to save EVERY reading, only discarding readings with really horrible accuracy. (If the user is driving at >=100 KPH, you don't have time to be picky about accuracy.)

P.S. Are you sure you need to consider vertical accuracy? I usually ignore the vertical accuracy as well as the vertical reading. I haven't done testing in a couple of years, but when I did, the vertical accuracy reading and altitude readings were quite poor.



来源:https://stackoverflow.com/questions/34111459/ios-core-location-get-most-accurate-location-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!