OGeek|极客世界-中国程序员成长平台

标题: ios - 为什么 MKMapView 不显示当前位置红色图钉? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 03:12
标题: ios - 为什么 MKMapView 不显示当前位置红色图钉?

MapView 正在显示我的当前位置,但没有出现红色图钉(或蓝色圆圈)。此设备已启用定位服务。但是,红色引脚显示在模拟器上运行相同的代码。我已经设置了必需的属性:

self.mapView.showsUserLocation = YES;

我正在使用自定义引脚,但是,“mapView:viewForAnnotation:”仅针对每个自定义注释调用,因此看起来此方法不会针对当前位置调用,这就是它没有显示红色引脚的原因。但是,很奇怪为什么相同的代码在模拟器上运行正确。

更新 刚刚使用 mapView 创建了空的单 View 项目。确实添加了 self.mapView.showsUserLocation = YES 但设备上没有显示当前位置。但是模拟器中显示了一个蓝色圆圈。我在 iPhone4 上使用 iOS 6.1.2。



Best Answer-推荐答案


mapView:viewForAnnotation: 为当前位置调用。

From the docs :

If the object in the annotation parameter is an instance of the MKUserLocation class, you can provide a custom view to denote the user’s location. To display the user’s location using the default system view, return nil.

在该委托(delegate)方法的实现中,检查传入的注解的类并进行相应处理(返回 nil 以使用蓝点或返回自定义 View )。

如果它没有被调用,则其他事情正在进行中。

关于ios - 为什么 MKMapView 不显示当前位置红色图钉?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17742900/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4