2012-10-29 74 views
2

我有一個iPhone應用程序可以縮放到用戶位置最近的城市,我希望用戶能夠雙擊用戶位置註釋並讓地圖放大一個街區左右。在MKMapView中跟蹤用戶位置註釋的選擇

如何獲得userLocation註釋以識別它正在被點擊?

+0

你試試我的代碼,我建議? –

+0

還沒有,但我會馬上! – barndog

回答

6
- (void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)mapView2 
{ 
    id<MKAnnotation> annotation = mapView2.annotation; 
    if ([annotation isKindOfClass:[MKUserLocation class]]) { 
      // this is where you can find the annotation type is whether it is userlocation or not... 
    } 
} 

上述方法是委託方法,你需要添加MKMapViewDelegate在接口文件

+0

那麼MapAnnotation不是一個類型。 MKAnnotation是,但每當我嘗試聲明MKAnnotation對象時,我得到一個錯誤,說未知類型'MKAnnotation' – barndog

+0

是否好去?你試過了嗎? –

+0

去我的朋友很好。 – barndog