问题描述
我正在使用适用于iOS的Google Map SDK。我在驾驶模式下绘制折线。
I am using Google Map SDK for iOS. I am drawing polylines in Driving mode.
但是当我停下来然后缩放谷歌地图时,我的当前位置光标会自动移动并重绘之字形折线,因为之前所有绘制的折线重叠,折线完全改变。当我进入背景和驾驶时会发生事情。
But when i stop,and Zoom google map then, my Current position cursor automatically moves and redraw zigzag polylines, due to that all previous polylines drawn get overlapped and polylines get completely changed.Same things happens when i go in background and drive.
我能知道它为什么会发生吗?如何在同一路径中同时在驾驶和步行模式下绘制平滑折线。
Could i know why is it happening? And How can I draw smooth polylines in driving and walking mode same time in same path.
我的代码 -
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
pointString=[NSString stringWithFormat:@"%f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude];
CLLocationDistance kilometers = [newLocation distanceFromLocation:oldLocation] / 1000;
NSLog(@"Distance Travelled in Kilometer :%f",kilometers);
[self.points addObject:pointString];
GMSMutablePath *path = [GMSMutablePath path];
for (int i=0; i<self.points.count; i++)
{
NSArray *latlongArray = [[self.points objectAtIndex:i]componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
[path addLatitude:[[latlongArray objectAtIndex:0] doubleValue] longitude:[[latlongArray objectAtIndex:1] doubleValue]];
}
if (self.points.count>2)
{
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeColor = [UIColor blueColor];
polyline.strokeWidth = 5.f;
polyline.map = mapView_;
self.mapContainerView = mapView_;
}
}
如果,我保持相同的位置,那么Googme地图光标位置自动移动并绘制这样的折线。
If , I remain in Same position, then Googme map Cursor position automaticalaly moves and draw polylines like this.
推荐答案
添加 NSLocationAlwaysUsageDescription 和 UIBackgroundModes - >location到Info.plist
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.
这篇关于Google Map SDK:在Google地图中绘制正确的折线,作为设备在后台移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!