[英]Remove travelled path from GMSPolyline on GMSMapView Swift iOS
[英]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.