Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum radius for iOS CLRegion feature of LocatinManager

I´m currently working the the region-feature of the location-manager. Unfortunately I am unable to get notifications for any border-crossings, which are smaller than 100m. I created regions with the radius of 20m / 50m or 70m and I always only get a notification, as soon as I cross the 100m-border. But I would like to have a finer radius - e.g. 20m and also receive a notification for that. Everything works quite well, if I have a range, which is greater than 100m - e.g. 150m. In this case I receive a notification as soon as I enter 150m as I would expect it.

I tried playing around with the "kCLLocationAccuracy"-settings on the LocationManager and the creation of CLRegions, but both does not seem to have any effect.

This is my code I use:

- (void) initializeLocationManager
{
    // Check to ensure location services are enabled
    if(![CLLocationManager locationServicesEnabled]) {
        [self showAlertWithMessage:@"You need to enable location services to use this app."];
        return;
    }

    if(![CLLocationManager regionMonitoringAvailable]) {
        [self showAlertWithMessage:@"This app requires region monitoring features which are unavailable on this device."];
        return;
    }

    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
}

- (void) setupGeoFence:(Station*)station
{ 
    CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake([station.gpsPosition.latitude doubleValue], [station.gpsPosition.longitude doubleValue]);
    CLRegion *geofence = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate radius:[range doubleValue] identifier:station.name];  
    [self.locationManager startMonitoringForRegion:geofence desiredAccuracy:kCLLocationAccuracyBest];
}

Does anyone have an idea how to receive notification on a closer boundary? Any help would be highly appriciated.

Thanks Hamtho

like image 406
Thomas Avatar asked Jan 12 '23 21:01

Thomas


1 Answers

Regions at that size are just not really possible. The location events are primarily triggered by the Wifi surrounding the device. GPS isn't really used unless absolutely necessary. So regions under 50M are really a crap shoot. I have spoken with CoreLocation engineers about this (along with some other odd behaviors surrounding region monitoring) and because of the dependency on Wifi, sizes that small are not recommended. They actually recommend 150M, even though it isn't documented.

If you really need location updates that fine grained, you may need to implement your own checks or fire up the GPS to get a very accurate reading. This comes along with a battery hit, so your mileage may vary. Good luck.

like image 154
Bill Burgess Avatar answered Jan 29 '23 04:01

Bill Burgess