如何在地图视图中抑制“当前位置”标注

点击表示用户位置的脉动蓝色圆圈,会出现“当前位置”标注。 有没有办法压制呢?

在用户位置更新后,您可以更改注释视图的属性:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { MKAnnotationView *userLocationView = [mapView viewForAnnotation:userLocation]; userLocationView.canShowCallout = NO; } 

您可以将title设置为空以压制标注:

 mapView.userLocation.title = @""; 

编辑:
更可靠的方法可能是在didUpdateUserLocation委托方法中将标题留空:

 -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { userLocation.title = @""; } 

或者在viewForAnnotation

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>) annotation { if ([annotation isKindOfClass:[MKUserLocation class]]) { ((MKUserLocation *)annotation).title = @""; return nil; } ... } 

在委托方法中设置标题可以让你确定你有一个真正的userLocation实例。

我有两种方法可以帮助你:

  1. 在mapViewDidFinishLoadingMap中禁止

     func mapViewDidFinishLoadingMap(_ mapView: MKMapView) { mapView.showsUserLocation = true //suppress the title mapView.userLocation.title = "My Location" //suppress other params 

    }

  2. 在didUpdate压缩

     func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) { //suppress the title mapView.userLocation.title = "My Location" //suppress other params }