2011-06-03 64 views
1

即时通讯使用mkmapview显示当前位置和坐标之间的路线。 即时通讯使用折线显示路线。我已经添加注释开始和目的地。即时通讯使用以下API获取坐标之间。mkmapview刷新mapview

http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/51.22545,4.40730,[51.22,4.41,51.2,4.41],51.23,4.42/car.js

现在如果我改变坐标已经存在的路线也是可见的。我如何删除现有的路线并添加新的路线? 在此先感谢。

回答

2

除非我在你的问题中丢失了一些东西,如果你已经有应用程序计算并显示一个MKPolyline那么你所需要做的就是删除旧的并添加一个新的。你的代码看起来像

// generating new data, do this however you like 
MKPolyline *routeLine = [self generateNewRoutLine]; 
MyPinAnnotation *startPin = [self generateNewStartPin]; 
MyPinAnnotation *endPin = [self generateNewEndPin]; 

// removing old overlays and adding new 
[myMapView removeOverlays:myMapView.overlays]; // removes all overlays 
[myMapView removeAnnotations:myMapView.annotations]; // removes all pins 
[myMapView addOverlay:routeLine]; 
[myMapView addAnnotations:[NSArray arrayWithObjects:startPin, endPin, nil]];