How do I calculate the distance between two points of latitude and longitude?

Ankit Vyas picture Ankit Vyas · Apr 16, 2010 · Viewed 19.3k times · Source

i have latitude and longitude of particular place and i want to calculate the distance so how can i calculate it?

Answer

Mads Mobæk picture Mads Mobæk · Apr 16, 2010
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
NSLog(@"Distance i meters: %f", [location1 distanceFromLocation:location2]);
[location1 release];
[location2 release];

You also need to add CoreLocation.framework to your project, and add the import statement:

#import <CoreLocation/CoreLocation.h>