如何隐藏“当前位置”地图视图中的标注

发布于 2024-12-18 19:27:54 字数 41 浏览 3 评论 0原文

点击代表用户位置的脉动蓝色圆圈会弹出“当前位置”标注。有办法抑制吗?

Tapping the pulsating blue circle representing the userLocation brings up a "Current Location" callout. Is there a way to suppress that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

淡淡的优雅 2024-12-25 19:27:54

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

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

There's a property on the annotation view you can change, once the user location has been updated:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    MKAnnotationView *userLocationView = [mapView viewForAnnotation:userLocation];   
    userLocationView.canShowCallout = NO;
}    
极致的悲 2024-12-25 19:27:54

您可以将标题设置为空白以抑制标注:

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要使用的实例。

You can set the title to blank to suppress the callout:

mapView.userLocation.title = @"";

Edit:
A more reliable way might be to blank the title in the didUpdateUserLocation delegate method:

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

or in viewForAnnotation:

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

    ...
}

Setting the title in the delegate methods lets you be certain you have a real userLocation instance to work with.

给妤﹃绝世温柔 2024-12-25 19:27:54

雨燕4

// MARK: - MKMapViewDelegate

func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
    if let userLocationView = mapView.view(for: mapView.userLocation) {
        userLocationView.canShowCallout = false
    }
}

Swift 4

// MARK: - MKMapViewDelegate

func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
    if let userLocationView = mapView.view(for: mapView.userLocation) {
        userLocationView.canShowCallout = false
    }
}
嗼ふ静 2024-12-25 19:27:54

斯威夫特 4 - Xcode 9.2 - iOS 11.2

// MARK: - MKMapViewDelegate

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
  if let userLocation = annotation as? MKUserLocation {
    userLocation.title = ""
    return nil
  }
  // ...
}

Swift 4 - Xcode 9.2 - iOS 11.2

// MARK: - MKMapViewDelegate

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
  if let userLocation = annotation as? MKUserLocation {
    userLocation.title = ""
    return nil
  }
  // ...
}
寄人书 2024-12-25 19:27:54

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

  1. 在mapViewDidFinishLoadingMap中抑制

    func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
    地图视图.showsUserLocation = true
    //隐藏标题
    mapView.userLocation.title = "我的位置"
    //抑制其他参数
    

    }

  2. 在didUpdate 中抑制

    func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
        //隐藏标题
        mapView.userLocation.title = "我的位置"
        //抑制其他参数
    }
    

I have two ways to help you:

  1. suppress in the mapViewDidFinishLoadingMap

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

    }

  2. suppress in the didUpdate

    func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
        //suppress the title
        mapView.userLocation.title = "My Location"
        //suppress other params
    }
    
谷夏 2024-12-25 19:27:54

SWIFT 版本

mapView 添加用户 MKAnnotationView 时,我们需要将用户 MKAnnotationView 属性 canShowCallout 设置为 false

func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
    for view in views {
        if view.annotation is MKUserLocation {
            view.canShowCallout = false
        }
    }
}

SWIFT Version

We need to set the user MKAnnotationView property canShowCallout to false when mapView adds the user MKAnnotationView

func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
    for view in views {
        if view.annotation is MKUserLocation {
            view.canShowCallout = false
        }
    }
}
李不 2024-12-25 19:27:54

嘿,有一个更新的简单解决方案

Swift:

mapView.userLocation.title = "";

.Net for iOS (Xamarin.iOS)

NativeMap.UserLocation.Title = "";

问候;)

Hey there is an updated easy solution

Swift:

mapView.userLocation.title = "";

.Net for iOS (Xamarin.iOS)

NativeMap.UserLocation.Title = "";

Regards ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文