MKMapView 和 CLLocationManager

发布于 2024-08-22 20:08:28 字数 694 浏览 3 评论 0原文

我想使用 MKMapView 使用默认的呼吸蓝色图钉来显示用户当前位置,并且我想同时记录用户移动。当我们启用 MKMapView 来显示用户位置时,有什么方法可以使用 MKMapView 使用的 GPS 管理器(不确定这是否是 CLLocationManager)?

我知道我可以创建自己的 CLLocationManager。但这感觉就像给我的应用程序增加了开销,我希望地图和我的跟踪保持同步。

我已经探索了以下想法,但没有成功:

  • 使用 [MKMapView showUserLocation:YES] 并在 userLocation 字段上添加 KVO。这不起作用,我想知道这是否是由于 userLocation 字段是只读的。
  • 使用[MKMapView showUserLocation:YES],创建一个MKMapViewDelegate,并在请求用户位置的注释视图时添加跟踪。这不起作用,因为注释视图显然只请求一次???
  • 使用 CLLocationManager 并尝试手动添加蓝色图钉。不幸的是,我没有在可用的引脚类型中找到蓝色引脚,因此我尝试手动创建用户注释,但没有成功。

有谁知道我如何实现这一目标并仍然受益于蓝色图钉,或者是我使用 CLLocationManager 并创建自己的图钉的唯一解决方案?

I want to use a MKMapView to display the user current location using the default breathing blue pin and I want to record the user movement at the same time. Is there any way that I could use the GPS manager (not sure if this is a CLLocationManager) the MKMapView uses when we enabled it to show user location?

I know that I can create my own CLLocationManager. But this feels like adding an overhead to my application and I would like the map and my tracking to remain in sync.

I already explored the following ideas without success:

  • Use the [MKMapView showUserLocation:YES] and add KVO on the userLocation field. This does not work and I am wondering if this is due to the fact that the userLocation field is read only.
  • Use the [MKMapView showUserLocation:YES], create a MKMapViewDelegate and add the tracking when the annotation view for the user location is requested. This does not work, because the annotation view is apparently requested only once???
  • Use a CLLocationManager and try to add the blue pin manually. Unfortunately, I did not find the blue pin in the available pin types, so I tried to create a user annotation manually without success.

Does anyone has any idea how I can achieve this and still benefit from the blue pin or is my only solution to use a CLLocationManager and create my own pin?

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

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

发布评论

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

评论(1

鹿港巷口少年归 2024-08-29 20:08:28

CLLocationManager 在其所有实例中使用相同的数据。 MKMapView 在内部使用 CLLocationManager 数据。也就是说,完成您想做的事情的解决方案是让 MKMapViewshowUserLocation: 做自己的事情。同时,创建 CLLocationManager 及其委托的实例。

委托消息将为您提供 MKMapView 蓝色图钉的 GPS 坐标位置。一切都将彼此同步。

CLLocationManager uses the same data across all of its instances. MKMapView uses CLLocationManager's data internally. That said the solution to do what you want to do is let MKMapView do its own thing with regards to showUserLocation:. At the same time, create an instance of CLLocationManager and its delegate.

The delegate messages will give you the GPS coordinate location of MKMapView's blue pin. Everything will be in sync with each other.

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