I am trying to calculate distance between two corelocation objects like this:
float meters = [destinationLocation distanceFromLocation:currentLocationNew];
distanceBtwTwoLocations = [NSString stringWithFormat:@"%f miles",meters];
But it is not giving me the exact distance. Why ? I just checked the values in console
currentLocationNew <+17.42369091, +78.43235230> +/- 0.00m (speed -1.00 mps / course -1.00) @ 10/06/11 12:43:59 PM India Standard Time
destinationLocation <+16.29850960, +80.43364716> +/- 0.00m (speed -1.00 mps / course -1.00) @ 10/06/11 12:44:07 PM India Standard Time
distanceBtwTwoLocations 247043 miles
Am I missing anything??
247,043 miles is about the distance to the moon and there are no two points on the planet that far apart unless you’re going the whole way round, ten times over (the circumference is only about 25,000 miles).
I’m pretty certain that your problem lies with the units you’re choosing to display, especially since the variable name you’re using is
metersrather thanmiles. 247,000 metres is only about 250kms, a couple of hours in a fast car, and matches your lat/long values, at least roughly.Your value of 247,043 has to be converted from meters to miles (1 mile is about 1609.344 meters) and dividing it by that gives you what you’re expecting, 153.5 miles.