监测重叠区域

时间:2013-12-25 07:55:51

标签: ios objective-c geolocation location

我在ios 6和7中使用区域监控。如果区域不重叠,它可以正常工作。但是,如果某些区域重叠,那么应用只会为一个区域调用委托方法didEnterRegion

我的代码:

_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;

for (XPLocationModel* locationModel in models) {
 if ([self.locationManager respondsToSelector:@selector(startMonitoringForRegion:)]) {
    [self.locationManager startMonitoringForRegion:locationModel.region];
} else if ([self.locationManager respondsToSelector:@selector(startMonitoringForRegion:desiredAccuracy:)]) {
    [self.locationManager startMonitoringForRegion:locationModel.region desiredAccuracy:XPGeofenceMaster_DesiredAccuracy];
}
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
   NSLog(@"%s id == %@", __PRETTY_FUNCTION__, region.identifier);
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
   NSLog(@"%s", __PRETTY_FUNCTION__);
}

1 个答案:

答案 0 :(得分:0)

如果需要,可以使用requestStateForRegion:方法获取有关所有状态的更新,如下所示。但是,您最好为进入和退出多次调用做好准备。

- (void)requestStateForAllLocations
{
    for (CLRegion *region in self.locationManager.monitoredRegions) { 
          [self.locationManager requestStateForRegion:region];
    }
}