是否有回调用于告知用户位置何时可用

发布于 2024-08-20 18:25:00 字数 728 浏览 6 评论 0原文

我正在寻找一个回调或协议,当用户的位置可用时会通知我。这样,当找到用户的位置时,我可以放大他们所在的位置。我可以用什么来做到这一点?

我想 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 技术交流群。

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

发布评论

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

评论(1

裂开嘴轻声笑有多痛 2024-08-27 18:25:00

查看 CLLocationManagerDelegate 协议,特别是 -locationManager:didUpdateToLocation:fromLocation: 。您可以从 newLocation 参数的 horizo​​ntalAccuracy 属性获取位置读数的准确性。

Look into the CLLocationManagerDelegate protocol, specifically -locationManager:didUpdateToLocation:fromLocation:. You can get the accuracy of the location reading from the newLocation parameter's horizontalAccuracy property.

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