MKMapView和CLLocationManager [英] MKMapView and CLLocationManager

查看:97
本文介绍了MKMapView和CLLocationManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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

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:


  • 使用 [MKMapView showUserLocation:YES] 并在 userLocation 字段中添加KVO。这不起作用,我想知道这是否是由于 userLocation 字段是只读的。

  • 使用 [MKMapView showUserLocation:YES] ,创建 MKMapViewDelegate 并在请求用户位置的注释视图时添加跟踪。这不起作用,因为注释视图显然只被请求一次???

  • 使用 CLLocationManager 并尝试添加蓝色手动固定。不幸的是,我没有在可用的引脚类型中找到蓝色引脚,因此我尝试手动创建用户注释但没有成功。

  • 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.

有没有人知道如何实现这一目标仍然可以从蓝色引脚中受益,或者是我使用 CLLocationManager 并创建自己的引脚的唯一解决方案?

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?

推荐答案

CLLocationManager 在其所有实例中使用相同的数据。 MKMapView 在内部使用 CLLocationManager的数据。那就是做你想做的解决办法就是让 MKMapView showUserLocation:做自己的事情。同时,创建 CLLocationManager 及其代理的实例。

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.

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

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

这篇关于MKMapView和CLLocationManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆