如何每 4-5 秒获取距用户位置的距离
我不会将其用于行车路线或类似用途。我有一些注释,并且希望当用户位于其中之一附近时触发,以便我可以提醒用户。
似乎每次 startUpdatingLocation 调用只调用一次 didUpdateToLocation ?至少当我在该方法中进行 NSLog 时,我只在控制台中得到一行。不,我不会带着 iPhone 到处走。
那么:设置对 userLocation 的连续监控并获得“回调”(当 3-4 秒过去或当用户移动(例如 10 米)时)的正确方法是什么?
I'm not using this for driving directions or similar. I have a few annotations and want a trigger when user is in the vicinity of one of those, so I can alert the user.
It seems didUpdateToLocation is called only once per startUpdatingLocation call? At least when I NSLog within that method, I only get one line in console. No, I'm not walking around with the iphone.
So: What is the correct way to set up a continuous monitoring of userLocation and get a "callback" (either when 3-4 seconds have passed or when user has moved say, 10 meters)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能知道,这是初始化和启动位置管理器的代码:
并像这样实现didUpdateToLocation:
每次有更新时,系统都会调用
didUpdateToLocation
地点。如果系统没有检测到位置的变化,didUpdateToLocation
将不会被调用。您唯一能做的就是像我在示例中所做的那样设置distanceFilter
和desiredAccuracy
以获得最高的准确度。更新
使用 kCLLocationAccuracyBest 而不是 kCLLocationAccuracyNearestTenMeters 以获得更高的准确性。
As you probably know, this is the code to initialize and start the location manager:
And implement didUpdateToLocation like this:
The system will call
didUpdateToLocation
every time there is an update to the location. If the system does not detect a change in locationdidUpdateToLocation
will not be called. The only thing you can do is to set thedistanceFilter
anddesiredAccuracy
like i did in the example to give you the highest accuracy.Update
Use kCLLocationAccuracyBest instead of kCLLocationAccuracyNearestTenMeters for more accuracy.