2013-03-28 89 views
1

我正在創建一個MKMapView應用程序,用戶可以在其中將註釋引腳拖放到任何特定位置。直到現在它的工作。但是我想要什麼,當用戶點擊刷新按鈕時,註釋引腳應該轉到當前用戶的位置。 所以按鈕點擊什麼,我不得不做出讓the pin should move from dragged location to user's location.MKMapView註釋拖放引腳,轉到用戶位置按鈕單擊

感謝

+1

使用GPS位置查找當前位置,之後將其移動該引腳到LAT-LON位置 – 2013-03-28 09:29:16

+0

這可能會幫助你 http://stackoverflow.com/questions/5326690/how-to-find-獲取經緯度location-using-mapkit-in-xcode – 2013-03-28 09:36:18

回答

0

我只是給你基本的邏輯,也許對你有所幫助。

當你的應用程序。當時第一次運行將當前的緯度和經度值添加到特定的變量字段。 (做持續的阻力和註釋的下降。過程再經過)

當你點擊刷新按鈕,然後先寫

[mapView removeAnnotations:mapView.annotations]; 

對於刪除您的註釋MapView類。

然後在得到latitudelongitude的值後,從您的變量。 並根據經緯度和長變量編寫添加註釋的代碼。

+0

您的解決方案正在運行。但問題是兩個針腳舊的和新的用戶位置。我只是想刪除舊的引腳。因爲我正在使用自定義圖像的引腳。 [mapView removeAnnotations:mapView.annotations];工作,但是當我縮放地圖上顯示拖動的引腳。這裏有任何幫助。 – user1997951 2013-03-28 10:43:59

+0

@ user1997951-你有不同的針顏色,然後這個答案http://stackoverflow.com/questions/5049280/remove-mkmapview-annotations-with-a-certain-pincolor或http://stackoverflow.com/questions/13278659 /(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )註釋;//刪除最後添加註釋從mkmapview – iPatel 2013-03-28 10:48:50

+0

- MKAnnotationView * a = [[MKAnnotationView alloc] initWithAnnotation:註解reuseIdentifier:@「currentloc」]; 如果(a == nil) a = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@「currentloc」]; a.image = [UIImage imageNamed:@「1234.png」]; a.draggable = YES; a.canShowCallout = YES; ''。這個方法每次調用時都會縮放,同時拖動引腳和當前用戶位置都會顯示。 – user1997951 2013-03-28 10:51:36

0
- (void)moveToCurrentLocation:(id)sender 
{  
[mymapview setCenterCoordinate:[mymapview.userLocation coordinate] animated:YES]; 
} 

IT將地圖視圖移動到您的當前位置(用戶的位置),並刪除當前標註爲iPatel在以前的評論說。

+0

如果OP手動設置緯度和長度值,那麼這段代碼沒有幫助更多 – iPatel 2013-03-28 10:32:00

+0

ohhk ..然後對不起我無法幫助你更多。但我也急於等待,看看它是如何發生的,如果你發現它,那麼請給我一個提示作爲對它的評論。 – Apple 2013-03-28 10:35:47

相關問題