【问题标题】:Monitoring overlapping regions监控重叠区域
【发布时间】:2014-01-13 06:14:22
【问题描述】:

我在 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__);
}

【问题讨论】:

    标签: ios objective-c geolocation location


    【解决方案1】:

    如果你愿意,你可以使用 requestStateForRegion: 方法来获取你所有状态的更新,像这样。但是,您最好准备好多次调用 enter 和 exit。

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

    【讨论】:

    • 这实际上触发了委托方法:-(void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2015-07-17
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多