views:

68

answers:

1

I'm not using this for driving directions or similar. I have a few annotations and want a trigger when user is in the vicinity of one of those, so I can alert the user.

It seems didUpdateToLocation is called only once per startUpdatingLocation call? At least when I NSLog within that method, I only get one line in console. No, I'm not walking around with the iphone.

So: What is the correct way to set up a continuous monitoring of userLocation and get a "callback" (either when 3-4 seconds have passed or when user has moved say, 10 meters)?

+3  A: 

As you probably know, this is the code to initialize and start the location manager:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];

And implement didUpdateToLocation like this:

- (void) locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*) oldLocation 
{
   // This will be called every time the device has any new location information. 
}

The system will call didUpdateToLocation every time there is an update to the location. If the system does not detect a change in location didUpdateToLocation will not be called. The only thing you can do is to set the distanceFilter and desiredAccuracy like i did in the example to give you the highest accuracy.

Update

Use kCLLocationAccuracyBest instead of kCLLocationAccuracyNearestTenMeters for more accuracy.

Martin Ingvar Kofoed Jensen
Thanks for answering! I couldn't think of a way right away to patch userLocation to be able to test that properly. I'll just implement the distance-alerter there and let someone test it live. It's actually better than using a time interval.Is accuracy=best and filter=10m the same thing, and if not, why not? (If you know.)
Henrik Erlandsson
You are right, kCLLocationAccuracyBest is better. Pretty sure that kCLDistanceFilterNone is the best. Documentation says its all notifications when using kCLDistanceFilterNone.
Martin Ingvar Kofoed Jensen
Well, actually I meant that moving 10 meters is a good criterion for frequent enough updates without getting them too often (or while standing still, which you'd get if you set both to 'best/none'?)So I just wondered which of "accuracy=best+filter=10m" and "accuracy=10m+filter=none" gave the most proper results, sort of, that was all. :)
Henrik Erlandsson
Ah. I have not tested the different values in real life, so can't help you with that.
Martin Ingvar Kofoed Jensen