简体   繁体   English

删除行进的GMSPolyline段

[英]Remove travelled GMSPolyline segment

I am using google map sdk for ios to provide directions between current user location and an end location. 我正在使用iOS的Google Map sdk在当前用户位置和最终位置之间提供路线。 I have so far achieved to draw a GMSPolyline between the current user location and the end location using the code below and it's working great. 到目前为止,我已经实现了使用下面的代码在当前用户位置和最终位置之间绘制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;

Is it possible to remove a part of the GMSPolyline that has been covered by the user through driving/walking? 是否可以删除用户通过驾驶/行走所覆盖的GMSPolyline的一部分? The GMSPolyline must gradually decrease in length as we trace the path. 随着我们跟踪路径,GMSPolyline的长度必须逐渐减小。

One way to achieve this is by redrawing the path repeatedly but this is not or may not be efficient. 实现此目的的一种方法是重复重绘路径,但这不是有效的方法,或者可能不是有效的方法。

Thanks. 谢谢。

So get the latlng point of the polyline in an array as described here : 作为说明,以便得到一个数组折线的经纬度点这里

 //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); 

Then, implement a while loop for the first point as you move along the path like this: 然后,沿着这样的路径移动,对第一个点实现while循环:

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

Note: I'm not that experienced with iOS and haven't tested this solution. 注意:我对iOS的经验还不丰富,还没有测试过此解决方案。 Treat it as a suggestion rather than a fix. 将其视为建议而不是解决方法。 Thanks! 谢谢!

Hope it helps! 希望能帮助到你!

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

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