2011-06-03 65 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]];