如何使用MapKit跟踪用户位置 [英] How to follow user location with MapKit

查看:234
本文介绍了如何使用MapKit跟踪用户位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MapKit显示用户的位置相对于它们周围的引脚。我想要能够模拟地图通过屏幕左下角的十字按钮提供的功能。我已经知道MapKit通过MKUserLocation提供了一个CLLocation对象与用户的位置,我只是想寻求如何应该关注那个位置的建议。我最初的倾向是使用NSTimer每500ms左右在那个坐标上定位地图。



有更好的方法吗?有没有一些内置的MapKit,我缺少,将完成这个?



非常感谢,
Brendan


<我想我实际上会使用CoreLocation CLLocationManager 并使用它的委托方法这样,你不需要一个 NSTimer

的开销,



您可以从 CLLocation 拉出经度和纬度, code>对象发送到 locationManager:didUpdateToLocation:fromLocation:方法,并将其传递到地图视图。


I'm using MapKit to display the user's location relative to pins around them. I'd like to be able to mimic the functionality that Maps provides via the crosshair button in the lower left-hand corner of the screen. I'm already aware that MapKit provides a CLLocation object with the user's location via MKUserLocation, I just wanted to seek advice on how I should keep focus on that location. My initial inclination was to use an NSTimer to center the map on that coordinate every 500ms or so.

Is there a better way to do this? Is there something built in to MapKit that I'm missing that will accomplish this?

Thanks so much, Brendan

解决方案

I think that I would actually use the CoreLocation CLLocationManager and use its delegate method locationManager:didUpdateToLocation:fromLocation:.

This way, you don't have the overhead of an NSTimer, and it only updates when there's a new location available.

You can pull the longitude and latitude from the CLLocation object sent to the locationManager:didUpdateToLocation:fromLocation: method and pass it to the map view.

这篇关于如何使用MapKit跟踪用户位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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