gpt4 book ai didi

iOS Geofence CLCircularRegion 监控。位置管理器 :didExitRegion does not seem to work as expected

转载 作者:IT王子 更新时间:2023-10-29 07:50:50 26 4
gpt4 key购买 nike

我目前正在尝试让我的应用程序使用 CoreLocation 监控特定区域,但是我发现它似乎没有按预期工作,在我看来它不能与小的一起工作为每个位置设置半径,即 10m。

我还整理了一个小测试应用程序,它在 map 上绘制了圆半径,这样我就可以直观地看到发生了什么。

我用于监控位置的代码如下:

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 区域等设置代码,因为我知道当我离开监控区域超过 100m 时它会起作用。

这是应用程序的屏幕截图,当我距离 map 上的紫色位置超过 10 米时,退出区域事件不会触发,但是如果我将我的位置切换到伦敦 它会触发,而且当我将我的位置 设置回当前蓝色位置时它也会触发。

Example Region

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

谢谢亚伦

最佳答案

我不认为区域监控对于这么小的半径效果很好。

  • GPS 芯片和kCLLocationAccuracyBestForNavigation 的最佳精度通常只有 10 米。
  • Apple 表示(在 Location & Maps PG 中)区域的最小距离应假定为 200 米
  • 我听说区域监控使用 WiFi 来获取它的位置(这对节能很有意义)。 WiFi精度更像是20m-100m。我不确定让另一个应用程序使用后台位置(即使用 GPS)会如何影响这一点。位置管理员可能会共享信息以提高准确性。
  • 区域监控可能需要 30 秒才能在区域内触发一次,离开区域后可能需要几分钟才能触发(以防止位置故障触发它)。
  • 当首次引入区域监控时,他们说它只适用于 100m 的区域,任何更小的区域都会被提升。这种情况可能仍然会发生。
  • 有一个已弃用的方法 startMonitoringForRegion:desiredAccuracy: 允许您指定超过区域边界的距离以开始生成通知。据推测,此功能已被整合到 startMonitoringForRegion: 中,但仍然存在。一个 10m 的区域可能最终有一个 10m 的缓冲区。
  • 如果您想这样做,请在您要监控的区域周围指定一个更大的区域,当设备在该区域唤醒时,启动后台位置更新 (GPS) 并使用 CLCircularRegion-containsCoordinate: 当设备在10m以内手动触发。此方法已获得 Apple 官方认可(参见 WWDC 2013 session 307)。

来自 CLCircularRegion 文档:

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.

来自Location & Maps PG :

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.

this post by Kevin McMahon 有更多内幕消息,他在 WWDC 2012 的实验室向 Core Location 工程师询问了有关区域监控的信息。此信息在此期间会发生变化,但有关区域类别的部分很有趣。这是一个编辑:

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 监控。位置管理器 :didExitRegion does not seem to work as expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23866097/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com