我可以像这样映射一条线:
CLLocationCoordinate2D pointsToUse[5];
pointsToUse[0] = CLLocationCoordinate2DMake(44.103100,-108.353706);
pointsToUse[1] = CLLocationCoordinate2DMake(44.103100,-108.354706);
pointsToUse[2] = CLLocationCoordinate2DMake(44.103100,-108.355706);
pointsToUse[3] = CLLocationCoordinate2DMake(44.103100,-108.356706);
pointsToUse[4] = CLLocationCoordinate2DMake(44.103100,-108.357706);
MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:pointsToUse count:5];
[self.mapView addOverlay:myPolyline];
但我的问题是如何继续实时添加到线路中。假设我得到包含一组新坐标的数组(这意味着我正在映射的对象已经移动)。我需要在地图上不断跟踪对象的进度。显然我可以这样做:
CLLocationCoordinate2D pointsToUse[2];
pointsToUse[0] = CLLocationCoordinate2DMake(34.103100,-118.357706);
pointsToUse[1] = CLLocationCoordinate2DMake(34.105100,-118.357706);
MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:pointsToUse count:2];
[self.mapView addOverlay:myPolyline];
因此,只需在地图上添加更多 MKPolylines。这是最好的方法吗?或者有什么方法可以只使用一条 MKPolyline 并更新它?