iOS应用程序使用地理围栏来通知用户有关预定义的附近位置.允许应用程序错过某个位置(用户没有收到有关附近位置的通知),但是希望保持较低的丢失率.
实现这一目标的一种方法是开始监控重要的变更位置,startMonitoringSignificantLocationChanges并且每次"位置变更"事件被触发时,查找位于报告位置的500米半径内的位置.
令我担心的是,每次发生重大位置变化时都需要对附近区域执行查询,这会影响电池.
另一种方法是注册地点,startMonitoringForRegion但Apple对同时跟踪的地区数量(合理)限制为20,我们有超过20个地点.因此需要对跟踪区域进行某种动态更新,但我仍然不确定最佳方法是什么.
有关如何做到这一点的任何想法,以便它保持低电池消耗,但也具有低位置的丢失率?
我想创建一个应用程序,当用户进入某个区域时,该应用程序执行特定操作.
由于我想要监控的区域位于服务器端(大约50,000个位置),并且区域数量太大而无法一次注册进行监控,我想开始监控接近当前位置的区域用户.
为了实现这一点,我正在考虑使用startMonitoringSignificantLocationChanges
监视用户是否已更改位置,然后使用locationManager:didUpdateToLocation:fromLocation:
注册新区域来监视和取消注册现在距离太远的区域.
我的问题:
didUpdateToLocation在应用程序处于后台时拨打网络服务
?谢谢.
在我的IOS应用程序中,我正在实现地理围栏.在当前的实现中,我使用的代码如下:
CLRegion* region3 = [[CLRegion alloc] initCircularRegionWithCenter:coordinates radius:100 identifier:@"region3"];
[self.locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyHundredMeters];
Run Code Online (Sandbox Code Playgroud)
然后我使用这些委托方法:
(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{
NSLog(@"didenterregion");
}
(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{
NSLog(@"didexitregion");
}
(void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{NSLog(@"monitoringDidFailForRegion");}
Run Code Online (Sandbox Code Playgroud)
但是,此代码仅适用于大于100米的半径.
以下是一些问题:
我也想到了.Apple表示可以支持多达20个地区.像这样的溶剂有什么优点/缺点(我还没有实现,但我想要你的意见).
伪代码将是这样的:
Declare the regions - save them in an array
Do not call start monitoring
Run Code Online (Sandbox Code Playgroud)
然后在委托方法中:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
for loop in all my regions {
if ([region containsCoordinate: newLocation.coordinate])
code for entering region
}
}
Run Code Online (Sandbox Code Playgroud)