In my application I want do geofencing. I have list of locations, for which I am setting geofencing regions. All location have radius 100m. Following is the code to set Region:
CLLocationCoordinate2D cord;
cord.latitude = [location.latitude doubleValue];
cord.longitude = [location.longtitude doubleValue];
CLLocationDistance regionRadius = location.radius;
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:cord radius:regionRadius identifier:[NSString stringWithFormat:@"%d",location.locId]];
[appDelegate.locationManager startMonitoringForRegion:region];
My problem is that, its not working properly. For debugging, in didEnterRegion delegate added distance calculation in between current location and region location some times this distance is more then 1500m.
Following is the code to calculate distance between current location and region location:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
CLLocation *loc1 = locationManager.location;
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:region.center.latitude longitude:region.center.longitude];
double dist = [loc1 distanceFromLocation:loc2];
}
Any idea, why -locationManager:didEnterRegion:
get triggered such a wrong way?