CLLocation getDistance not right

Discussion in 'iOS Programming' started by man2manno, Jun 12, 2009.

  1. man2manno macrumors member

    Mar 21, 2009
    I am trying to use CLLocationDistance to get a distance from a starting point. But for some reason when I load the app onto my iphone and run it and dont even move the iphone, after about 3 seconds the distance label displays a number like "2333.34 m" which is obviously not right due to the fact I have not moved the iphone.

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    	if (startingPoint == nil)
    		self.startingPoint = newLocation;
    	CLLocationDistance distance = [newLocation getDistanceFrom:startingPoint];
    		NSString *distanceString = [[NSString alloc] initWithFormat:@"%g", distance];
    		distanceLabel.text = distanceString;
    Anyone got an idea of why it is doing that?
    Thanks a lot.
  2. jsnuff1 macrumors 6502a

    Oct 4, 2003
    What you need to do is check CLLocation accuracy value before invoking getDistance. What is happening is that CLLocation returns progressively better and better locations values when it starts up, and initial locations values could very well be off by over 2k meters when it returns rough cell locations information.
  3. man2manno thread starter macrumors member

    Mar 21, 2009
    Thanks for the response.

    So what your saying is that I need to say something like:

    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    and that as the program continues to update that the value will become more and more accurate?

Share This Page