2

我有一个 iPhone 应用程序可以缩放到用户所在位置最近的城市,我希望用户能够双击userLocation 注释并将地图放大到大约一个街区左右。

如何让userLocation注释识别它正在被窃听?

4

2 回答 2

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...
     }
}

the above method is a delegate method and you need to add MKMapViewDelegate in your interface file

于 2012-10-29T20:41:40.917 回答
0

这是 Swift 4 中的代码:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if view.annotation is MKUserLocation {
        // You tapped on the user location
    }
}
于 2018-10-09T22:51:16.890 回答