我可以映射这样的一行:
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];
但我的问题是如何实时添加到该行。假设我得到的数组包含一组新的coordintates(这意味着我映射的对象已移动)。我需要在地图上跟踪对象的进度。显然我可以这样做:
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并让它更新?