在我的IOS应用程序中,我正在实现地理应用程序。在当前的实现中,我使用的代码如下:
CLRegion* region3 = [[CLRegion alloc] initCircularRegionWithCenter:coordinates radius:100 identifier:@"region3"];
[self.locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyHundredMeters];然后我使用这些委托方法:
(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");}然而,这个代码只在半径大于100米的情况下才能正常工作。
以下是一些问题:
我也认为。苹果公司表示,多达20个地区可以得到支持。像这样的解决方案有什么优点/缺点(我还没有实现它,但我想听听你的意见)。
伪码应该是这样的:
Declare the regions - save them in an array
Do not call start monitoring然后在委托方法中:
- (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
}
}提前谢谢。
发布于 2013-09-08 00:55:32
1.
我怀疑第二个(didUpdateToLocation:-based)实现将比第一个实现更昂贵(就电池寿命而言),因为您只会在第一个(startMonitoringForRegion:-based)实现中运行代码,并且只有当设备位于您正在跟踪的(最多20个)区域的半径范围内时才会运行代码。
而在第二个实现中,“委托呼叫 (这将经常发生)和委托方法中的代码将被运行。
B.T.W.,你说代码在半径超过100米的范围内运行良好,但苹果文档说,它应该在iOS6中工作,“设备4s及以上支持半径在1到400米之间”。
你的“100米”号码是你的实际结果还是你使用的设备的限制(比iPhone 4s或旧的iOS版本更老的东西)?
2.
在后台做任何事情都会消耗电池但是苹果公司已经为此对CoreLocation进行了优化 (如果您在应用程序的info.plist文件中设置正确的标志)
3.
我想两种方法都差不多一样准确,除了"startMonitoringForRegion:“报告该地区已进入或退出可能需要几分钟的时间外。
4.
是的,在第二个实现中,您可以有任意多个区域来跟踪。然而,你在后台运行的代码越多,电池就越热,你就越有可能更快地耗尽电池。
https://stackoverflow.com/questions/18679188
复制相似问题