2016-11-09 28 views
-2

我想要實現像移動地圖時的功能,引腳也會移動並放置在我想要的位置並從當前位置變爲用戶。當拖動地圖然後釋放時如何移動引腳並放下

我曾嘗試以下代碼:

- (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
    if ([annotation isKindOfClass:[MKUserLocation class]]) { 
     return nil;  
} 
+0

你可以成爲你想要的東西更清楚了嗎? –

+0

請解釋你的問題。 –

+0

我想要....當我移動地圖時,我當前的位置引腳也會移動並放在我想要的位置。並且從當前位置開始拾取位置....任何幫助都會感激 –

回答

1

此代碼是在SWIFTY,但在的OBJ-C類似。 手勢識別添加到的MapView:

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(mapViewTapped)) 
mapView.addGestureRecognizer(tapGesture) 

然後,當你在地圖上的觸摸,將其轉換爲相對點上的MapView然後查詢地圖位置:

func mapViewTapped(gestureRecognizer: UIGestureRecognizer) { 
    let touchPoint = gestureRecognizer.location(in: mapView) 
    let coordinate = mapView.convert(touchPoint, toCoordinateFrom: mapView) 
    addPin(at: coordinate) 
} 

最後,銷添加到地圖:

func addPin(at coordiante: Coordinate) { 
    let newAnnotation = MKPointAnnotation() 
    newAnnotation.coordinate = coordiante 

    mapView.addAnnotation(newAnnotation) 
} 
相關問題