문제

I'm trying to set up region monitoring. Looks pretty straightforward; but when I check the number of regions I monitor, the count is always 0.

Code:

if ([CLLocationManager regionMonitoringAvailable] &&
    [CLLocationManager regionMonitoringEnabled] ) {

    CLLocationCoordinate2D coordinate;
    double radius;

    for(Item *item in ad.proxiArray) {

        radius = [item.distance floatValue];

        coordinate= CLLocationCoordinate2DMake([item.latitude doubleValue],
                                                [item.longitude doubleValue]);
        CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:radius identifier:item.place];

        NSLog(@"Adding: %@", region);

        [self.locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyNearestTenMeters];

        [region release];
    }   
    NSLog(@"region count %i",[[self.locationManager monitoredRegions] count]);
    for (CLRegion *re in [self.locationManager monitoredRegions]) {
        NSLog(@"Monitoring: %@", re);
    }
} else {
    NSLog(@"Region monitoring unavailable");
}

When run, NSLog will show that I am actually adding all items (about 10). But at the end of the loop, as stated above:

2010-12-21 12:14:38.172 xxxxxx[8112:307] region count 0

What's wrong????

도움이 되었습니까?

해결책

My impression is that

  • CLLocationManager in itself is not thread-safe. Region monitoring and location monitoring will interfere and may occasionally lead to blocks (from my observation, there must be kind of a timeout, as the program continues to work after a bit more than 30 seconds)
  • Regions will be added asynchronously, thus checking the number of regions directly when having finished adding them may lead to a wrong result.
  • The accuracy is very bad (resolution of several km) when regions are actually added to be monitored

Because of these problems and the fact that region monitoring is not very accurate, I gave up the idea of using that feature.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top