Google Map SDK: Draw correct polyline in google map as Device Moves in Background

不打扰是莪最后的温柔 提交于 2019-11-29 07:18:00

add a NSLocationAlwaysUsageDescription and a UIBackgroundModes -> "location" to Info.plist

AND

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
    manager.allowsBackgroundLocationUpdates = YES;
}

Before allowing background location updtaes: enter image description here

After Allowing background location updtaes: enter image description here

Most of this itinerary has been drawn in the background.

Two things are going on. First, the GPS chip does not always return the same location when standing still. The determined GPS location always fluctuates a bit. iOS does an effort to detect that you're standing still, and then supply the same location, but I think that is done to a lesser extend in Driving mode.

Second, by using the convoluted way to store the samples as strings, you go through a %f conversion, which looses accuracy. That can exaggerate any differences between locations. If you use the CLLocation objects directly, you're likely getting a better result (and much cleaner code):

[self.points addObject:newLocation];
GMSMutablePath *path = [GMSMutablePath path];

for (CLLocation *col in self.points)
{
    [path addLatitude:col.latitude longitude:col.longitude];
}

Also, make sure you set the correct settings on the CLLocationManager:

theLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
theLocationManager.distanceFilter = kCLDistanceFilterNone;
theLocationManager.activityType = CLActivityTypeOtherNavigation;
theLocationManager.allowsBackgroundLocationUpdates = YES

One other thing. It is also very strange that you change the view in the didUpdateToLocation: method:

self.mapContainerView = mapView_;

You should just use setNeedsDisplay on the existing view, after updating the path.

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