繁体   English   中英

删除行进的GMSPolyline段

[英]Remove travelled GMSPolyline segment

我正在使用iOS的Google Map sdk在当前用户位置和最终位置之间提供路线。 到目前为止,我已经实现了使用下面的代码在当前用户位置和最终位置之间绘制GMSPolyline的功能,并且效果很好。

GMSPath *encodedPath = [GMSPath pathFromEncodedPath:encodedPathSting];
self.polyline = [GMSPolyline polylineWithPath:encodedPath];
self.polyline.strokeWidth = 4;
self.polyline.strokeColor = [UIColor colorWithRed:55.0/255.0 green:160.0/255.0 blue:250.0/255.0 alpha:1.0];;
self.polyline.map = self.mapView;

是否可以删除用户通过驾驶/行走所覆盖的GMSPolyline的一部分? 随着我们跟踪路径,GMSPolyline的长度必须逐渐减小。

实现此目的的一种方法是重复重绘路径,但这不是有效的方法,或者可能不是有效的方法。

谢谢。

作为说明,以便得到一个数组折线的经纬度点这里

 //route is the MKRoute in this example //but the polyline can be any MKPolyline NSUInteger pointCount = route.polyline.pointCount; //allocate a C array to hold this many points/coordinates... CLLocationCoordinate2D * routeCoordinates = malloc(pointCount * sizeof(CLLocationCoordinate2D)); //get the coordinates (all of them)... [route.polyline getCoordinates: routeCoordinates range: NSMakeRange(0, pointCount) ]; //this part just shows how to use the results... NSLog(@"route pointCount = %d", pointCount); for (int c = 0; c < pointCount; c++) { NSLog(@"routeCoordinates[%d] = %f, %f", c, routeCoordinates[c].latitude, routeCoordinates[c].longitude); } //free the memory used by the C array when done with it... free(routeCoordinates); 

然后,沿着这样的路径移动,对第一个点实现while循环:

 int c = 0; while (pointCount.size() > 0) { pointCount.get(0).remove(); } 

注意:我对iOS的经验还不丰富,还没有测试过此解决方案。 将其视为建议而不是解决方法。 谢谢!

希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM