【发布时间】:2017-03-02 05:13:21
【问题描述】:
我正在使用适用于 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_;
}
}
如果,我保持在同一位置,那么谷歌地图光标位置会自动移动并像这样绘制折线。
【问题讨论】:
-
我建议记录你的行车路线的所有坐标并尝试绘制它们,看看你是否得到相同的重叠折线,如果是,那么你的代码是正确的。
-
@satheeshwaran 你能回答吗
-
我没有在代码中看到任何可疑之处,您需要检查用于绘制线条的坐标。看看他们是否遵循相同的模式。
标签: ios objective-c google-maps-sdk-ios google-polyline