跟踪MKMapView中用户位置注释的选择

时间:2012-10-29 19:18:22

标签: ios mkmapview mkannotation userlocation

我有一个iPhone应用程序缩放到用户所在位置的最近城市,我希望用户能够双击 userLocation annotation 并让地图放大到一个块或所以。

如何让userLocation注释识别出它被点击?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

这是Swift 4中的代码:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if view.annotation is MKUserLocation {
        // You tapped on the user location
    }
}