iOS Geofence CLCircularRegion监控。 locationManager:didExitRegion似乎没有按预期工作 [英] iOS Geofence CLCircularRegion monitoring. locationManager:didExitRegion does not seem to work as expected

查看:411
本文介绍了iOS Geofence CLCircularRegion监控。 locationManager:didExitRegion似乎没有按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正试图让我的应用程序使用 CoreLocation 监视特定区域,但我发现它似乎没有按预期工作,在我看来,它

I am currently trying to get my app to monitor particular regions using CoreLocation however I am finding that it does not seem to work as expected, it seems to me that it cannot work with small a small radius set for each location i.e. 10m.

我也把一个小的测试应用程序绘制在圆半径 >在地图上,所以我可以看到发生了什么。

I've also put together a little test app which plots the circle radius on a map so I can visually see what is happening.

我用于监控地点的代码如下:

The code I am using for monitoring locations is as follows:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

// Set-up a region
CLLocationDegrees latitude = 52.64915;
CLLocationDegrees longitude = -1.1506367;
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);

CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:centerCoordinate
                                                                 radius:10 // Metres
                                                             identifier:@"testLocation"];

[self.locationManager startMonitoringForRegion:region];

我没有在这里放置代码 DidEnter

I have not put up the code here for DidEnter region etc as I know that works when I go over 100m away from the monitored region.

这是一个应用程序的屏幕截图,当我远远超过10米远离地图上的紫色位置,但是如果我将位置切换到伦敦,那么退出区域事件不会触发,而且当我设置了 >位置回到蓝色位置当前所在的位置。

Here is a screen shot of the app when I am well over 10 meters away from the purple location on the map, the did exit region events do not fire, however if I switch my location to London it fires and also when I set my location back to where the blue location is currently it also fires.

有人知道最小区域半径是否有限制,或者我做错了。

Does anyone know if there is a limitation with the minimum region radius at all or perhaps I am doing something wrong.

谢谢Aaron


Thanks Aaron

推荐答案

我不认为区域监控将在这么小的半径内工作。

I don't think region monitoring will work well for such a small radius.


  • GPS芯片和 kCLLocationAccuracyBestForNavigation 的最佳精确度通常只有10米。

  • Apple在位置和地图PG ),地区的最小距离应假定为200米

  • 听说区域监控正在使用WiFi来获得它的位置(这对于节电有意义)。 WiFi精度更像是20m-100m。我不知道如何让另一个应用程序使用后台位置(即使用GPS)会影响这一点。

  • 区域监控可能需要30秒钟才能在区域内触发,而在离开区域后需要几分钟时间才能触发

  • 当区域监控首次引入时,他们说它只能在100m区域工作,任何更小的区域会被爆炸。这可能仍然会发生。

  • 有一个已弃用的方法 startMonitoringForRegion:desiredAccuracy:,允许您指定通过区域边框的距离生成通知。大概这个功能已经被转换到 startMonitoringForRegion:,但仍然存在。一个10米的区域最终可能会有一个10米的缓冲区。

  • 如果要这样做,请在要监视的位置指定一个较大的区域,当设备在该区域唤醒时,启动后台位置更新(GPS),并使用 CLCircularRegion -containsCoordinate: 。此方法已获苹果官方认可(请参阅 WWDC 2013 会话307)。

  • The best accuracy with the GPS chip and kCLLocationAccuracyBestForNavigation is often just 10 meters.
  • Apple says (in the Location & Maps PG) that the minimum distance for regions should be assumed to be 200m
  • I've heard that region monitoring is using WiFi to get it's position (which makes sense for power savings). WiFi accuracy is more like 20m-100m. I'm not sure how having another app using background location (i.e. using GPS) would affect this. Probably, the location manager would share information to make the accuracy better.
  • Region monitoring can take 30 seconds to fire once inside a region, and a couple of minutes to fire after leaving a region (to prevent location glitches from triggering it).
  • When region-monitoring was first introduced, they said that it would only work with 100m regions and anything smaller would be bumped up. This probably still happens.
  • There's a deprecated method startMonitoringForRegion:desiredAccuracy: which allowed you to specify the distance past the region border to start generating notifications. Presumably this feature has been rolled into startMonitoringForRegion: but is still there. A 10m region might end up with a 10m buffer.
  • If you want to do this, specify a larger region around where you want to monitor, and when the device wakes up in that region, start background location updates (GPS) and use CLCircularRegion's -containsCoordinate: to trigger when the device is within 10m manually. This method is officially sanctioned by Apple (see WWDC 2013 Session 307).

CLCircularRegion docs:


请记住,位置管理器在跨越区域边界时不会立即生成通知。相反,它应用时间和距离标准,以确保过境是有意的,并且应该真正触发通知。

Remember that the location manager does not generate notifications immediately upon crossing a region boundary. Instead, it applies time and distance criteria to ensure that the crossing was intended and should genuinely trigger a notification. So choose a center point and radius that are appropriate and give you enough time to alert the user.

位置&地图PG


地区事件可能不会在跨越区域边界后立即发生。为了防止虚假通知,iOS不会传送区域通知,直到满足某些阈值条件。具体来说,用户的位置必须跨越区域边界,远离边界移动最小距离,并且在报告通知之前保持在该最小距离至少20秒。

特定阈值距离由硬件和当前可用的定位技术确定。例如,如果禁用Wi-Fi,则区域监视显着不太准确。但是,为了测试的目的,你可以假设最小距离大约是200米。

Region events may not happen immediately after a region boundary is crossed. To prevent spurious notifications, iOS doesn’t deliver region notifications until certain threshold conditions are met. Specifically, the user’s location must cross the region boundary, move away from the boundary by a minimum distance, and remain at that minimum distance for at least 20 seconds before the notifications are reported.
The specific threshold distances are determined by the hardware and the location technologies that are currently available. For example, if Wi-Fi is disabled, region monitoring is significantly less accurate. However, for testing purposes, you can assume that the minimum distance is approximately 200 meters.

http://www.kevfoo.com/2012/07/Core-Location-The-Missing-Details/\">由Kevin McMahon发表的文章,他要求Core Location工程师在实验室进行区域监测WWDC 2012.此信息将在此期间更改,但有关区域类别的部分是有趣的。这是修改:

There's further inside scoop from this post by Kevin McMahon, who asked the Core Location engineers about region monitoring at a lab at WWDC 2012. This info will have changed in the meantime, but the part about region categories is interesting. Here's an edit:


精细区域(0 - 150米)

- 地板100米这个类别的范围有效地是100-150米。

- 对于地区,这个大小的性能很大程度上取决于与位置相关的硬件

- 需要的时间core在跨越区域边界之后,检测和调用适当的委托方法的位置平均大约为2-3分钟。

- 一些开发人员已经独立地想出,较小的区域会看到更快的回调,区域覆盖一个大面积以改善区域交叉通知。

Fine Region (0 - 150m)
- With the floor of 100m this category's range is effectively 100-150m.
- For regions this size performance is heavily dependent on the location-related hardware
- The amount of time that it takes Core Location to detect and call the appropriate delegate method is roughly 2-3 minutes on average after the region boundary has been crossed.
- Some developers have figured out independently that smaller regions would see quicker callbacks and would cluster smaller regions to cover one large area to improve region crossing notifications.

这篇关于iOS Geofence CLCircularRegion监控。 locationManager:didExitRegion似乎没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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