是否有回调用于告知用户位置何时可用
我正在寻找一个回调或协议,当用户的位置可用时会通知我。这样,当找到用户的位置时,我可以放大他们所在的位置。我可以用什么来做到这一点?
我想 CoreLocation 中有一些东西可以做到这一点,但我找不到如何做到这一点。
[更新]
我已经使用 locationManager:didUpdateToLocation:fromLocation:
实现了
并创建了一个 CLLocationManager 实例。
locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
但我仍然没有收到任何位置更新。另外,如果我使用 didUpdateLocation:
那么每次更新它都会重新缩放到用户。有没有比检查是否是第一次更新更好的方法?
[更新2] 将 self.
添加到 locationManager
让它继续运行,我检查 fromLocation:
是否为 nil
来判断是否这是第一次更新。
I'm after a callback or protocol that will notify me when the user's location is available. So that when a user's location is found I can zoom into where they are. What can I use to do this?
I was thinking there waas something in CoreLocation that could do it, but I can't find how to do it.
[Update]
I've implemented <CLLocationManagerDelegate>
with locationManager:didUpdateToLocation:fromLocation:
and created an CLLocationManager instance.
locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
but I'm still not getting any location updates. Also if I use didUpdateLocation:
then it will re-zoom to the user each update. Is there a better way than having a check to see if it's the first update?
[Update 2]
adding self.
to the locationManager
got it going and I checked to see if fromLocation:
is nil
to tell if it was the first update.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 CLLocationManagerDelegate 协议,特别是 -locationManager:didUpdateToLocation:fromLocation: 。您可以从
newLocation
参数的horizontalAccuracy
属性获取位置读数的准确性。Look into the
CLLocationManagerDelegate
protocol, specifically-locationManager:didUpdateToLocation:fromLocation:
. You can get the accuracy of the location reading from thenewLocation
parameter'shorizontalAccuracy
property.