Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
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.

Code:
- (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.
 
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.
 
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.