PaulG
PaulG

Reputation: 7122

iOS: Region monitoring with simulator is way off

I've been having nothing but problems trying to do region monitoring on iPhone. First of all I have never (not even once) had either didEnterRegion or didExitRegion fire on my iPhone 4 device.

I decided to test on the simulator instead of wasting work hours walking around downtown (although I would like to see this work in a real scenario). First of all, the simulator is way off in terms of accuracy, you'd think it'd be pretty accurate (or am I wrong to have assumed that?).

The following was done in the simulator by changing the location under the Debug menu

I finally got didEnterRegion to fire, though I was about 8 city blocks away from the circle in question. When I exited the region didExitRegion fired about 200 times in a row. Is this a simulator bug? I'm almost ready to give up on this and start calculating this stuff myself because it's getting ridiculous.

Any ideas as to why the accuracy is so bad and why my methods are being fired so many times?

Here's the relevant code:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions
{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    CLLocationDegrees latitude = 45.50568;
    CLLocationDegrees longitude = -73.57033;
    CLLocationCoordinates2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);

    CLLocationDistance regionRadius = 200.0;

    CLRegion *myRegion = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate radius:regionRadius identifier:@"aroundWork"];

    [locationManager startMonitoringForRegion:myRegion];

    return YES:
}

-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    NSLog(@"Entered region: %@", region.identifier);
}

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
    NSLog(@"Exited region: %@", region.identifier);
}

Upvotes: 0

Views: 2219

Answers (1)

Lefteris
Lefteris

Reputation: 14687

First of all I assume you are testing it on the simulator with a GPX file, as any other way would be wrong.

Now, because I have done extensive research on Region Monitoring:

Region monitoring is not very effective. It can miss a region enter or exit easily.

We have done a lot of tests and a lot of walks and driven with our cars through the city multiple times to test.

Sometimes it works beautifully, sometimes it fails miserably.

I suggest you play around a bit with the region border (radius) settings and do REAL tests (walk or drive around certain points) to see which behaves better.

Our tests showed that smaller values behave better (100 to 200 meters radius) and also that the region monitoring behaves better when you are actually driving, rather than walking.

Remember it uses the cell tower antennas to position you, which is far less accurate than gps.

Upvotes: 3

Related Questions