I’m currently implementing startMonitoringFromRegion:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
self.currentLocation = newLocation;
if (![CLLocationManager regionMonitoringAvailable] ||
![CLLocationManager regionMonitoringEnabled])
return;
CLLocationDegrees radius = 5;
if (radius > self.locationManager.maximumRegionMonitoringDistance)
radius = self.locationManager.maximumRegionMonitoringDistance;
CLRegion* region = [[CLRegion alloc] initCircularRegionWithCenter:self.currentLocation.coordinate
radius:radius
identifier:@"Indentifier"];
[self.locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyHundredMeters];
[region release];
}
When I enter a new region didEnterRegion will get called.
My question here is, what should I do in didEnterRegion?
I have an array of all my coordinates. Should I extract region.center and compare that coordinate to my array of coordinates, and see which one of the coordinates that’s closest to region.center?
I noted that CLRegion has a wonderful method called containsCoordinate.
So instead of looping through all my McDonald’s array coordinates in didEnterRegion and check if their distance is less than x kilometers from region.center, I can now just use containsCoordinate.
Now, I haven’t tried this yet, but to me it seems logical.