Che*_*ile 6 objective-c ios google-polyline google-maps-sdk-ios
我正在使用适用于iOS的Google Map SDK.我在驾驶模式下绘制折线.
但是当我停下来,然后缩放谷歌地图时,我的当前位置光标会自动移动并重绘之字形折线,因为所有先前绘制的折线都会重叠并且折线会完全改变.当我进入背景和驱动时会发生事情.
我能知道为什么会这样吗?如何在同一路径中同时在驾驶和步行模式下绘制平滑折线.
我的守则 -
- (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_;
}
}
Run Code Online (Sandbox Code Playgroud)
如果,我保持在相同的位置,那么Googme map Cursor positionalalarala自动移动并绘制这样的折线.
小智 0
添加NSLocationAlwaysUsageDescription和UIBackgroundModes -> "location"到 Info.plist
和
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
manager.allowsBackgroundLocationUpdates = YES;
}
Run Code Online (Sandbox Code Playgroud)
在允许后台位置更新之前: 在此处输入图像描述
允许后台位置更新后: 在此处输入图像描述
大部分行程都是在后台绘制的。