CLLocationManager didUpdateToLocation 与 MKMapView 的 didUpdateUserLocation
我从 CLLocationManager 和 MKMapView 获取用户的位置。我应该使用哪一个来设置地图的中心坐标?
此外,模拟器中的两种方法的答案也不同。 CLLocationManager 返回正确的位置,而 MKMapview 的 didUpdateUserLocation 返回位于库比蒂诺的 Apple 办公室。
I get the user's location from both CLLocationManager and MKMapView. Which one should I use to set the Map's center coordinate?
Also, the two methods in the simulator differ in their answers. The CLLocationManager returns the correct location whereas the MKMapview's didUpdateUserLocation returns the Apple office in cupertino.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在使用地图时,我会使用 MapKit 位置。
地图例程旨在在处理地图时使用;而 CoreLocation 例程的用途与地图无关。 MapKit 将报告影响地图的位置更改(如果 showUserLocation 为 YES 或跟踪模式为 MKUserTrackingModeFollowWithHeading,则调用 didUpdateUserLocation)。 CoreLocation 的服务能够在应用程序处于后台时报告更改。
最重要的是,您应该使用适合您正在做的事情的选项。在我的应用程序中,我使用两种服务:显示地图时使用 MapKit,以及每当未显示地图或应用程序处于后台时使用 CoreLocation。
有趣的是,自 iOS 5 发布以来,模拟器支持多种位置选项;查看模拟器应用程序的“调试”菜单,我还在 https://stackoverflow.com/a/8175468/ 中描述了其中一些选项338468。
I would use the MapKit location when working with the map.
The map routines are intended for use while working with the map; while the CoreLocation routines are intended for use irrespective of the map. MapKit will report location changes that affect the map (didUpdateUserLocation is called if showUserLocation is YES or the tracking mode is MKUserTrackingModeFollowWithHeading). CoreLocation's services are capable of reporting changes while the application is in the background.
The bottom line is you should use the option which is appropriate for what you are doing. In my application, I use both services: MapKit when the map is displayed, and CoreLocation whenever the map is no displayed or the app is backgrounded.
Anecdotally, since the release of iOS 5, the simulator supports a number of location options; look on the Debug menu for the simulator application, I also described some of these options at https://stackoverflow.com/a/8175468/338468.
我使用
CLLocationManager
,正是因为以1个无限循环Dr为中心。它也给了你更多的选择,你可以使用startMonitoringSignificantChanges...等等。I use
CLLocationManager
, precisely because of the centering on 1 infinite loop Dr. It also gives you more options, you can use startMonitoringSignificantChanges... etc.如果您要处理中国大陆的位置,我会推荐 MapKit 位置。它为您处理 GPS 偏移量的计算(出于国家安全原因由法律添加)。有关此问题的更多信息,请访问https://en.wikipedia.org/wiki/Restrictions_on_geographic_data_in_China
If you are dealing with locations in Mainland China, I would recommend the MapKit location. It handles the calculation of the GPS offset (which is added by law for national security reasons) for you. More about this issue at https://en.wikipedia.org/wiki/Restrictions_on_geographic_data_in_China