Ios MKMapView中用户位置注释的轨迹选择

Ios MKMapView中用户位置注释的轨迹选择,ios,mkmapview,mkannotation,userlocation,Ios,Mkmapview,Mkannotation,Userlocation,我有一个iPhone应用程序,可以缩放到用户所在位置最近的城市,我希望用户能够双击userLocation注释,并将地图放大大约一个街区 如何让userLocation注释识别它正在被点击?-(void)mapView:(MKMapView*)mapView 1未选择AnnotationView:(MKAnnotationView*)mapView 2 - (void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotat

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

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

-(void)mapView:(MKMapView*)mapView 1未选择AnnotationView:(MKAnnotationView*)mapView 2
- (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...
     }
}
{ id注释=mapView2.0注释; if([annotation isKindOfClass:[MKUserLocation类]]){ //在这里可以找到注释类型,无论它是否为userlocation。。。 } }

上述方法是一种委托方法,您需要在界面文件中添加
MKMapViewDelegate
以下是Swift 4中的代码:

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

你是否按照我的建议尝试了我的代码?还没有,但我现在就去!嗯,MapAnnotation不是一种类型。MKAnnotation是,但每当我尝试声明MKAnnotation对象时,我都会在表示未知类型“MKAnnotation”时出错