-1

I need to calculate distance between Latitude and Longitude using Great Circle Formula.

One way I know, is to use the following:

 CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];

 CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];

 CLLocationDistance distance = [locA distanceFromLocation:locB];

But, I am not sure if it used Great Circle Distance algorithm for calculations. Does anyone have any idea about this? Help is much appreciated.

J.J.
  • 1,128
  • 2
  • 23
  • 62
Sundeep Saluja
  • 1,089
  • 2
  • 14
  • 36
  • 1
    google maps use the great circle distance formula and apple follows the curvature of the Earth formula to find out the distance – Rushabh Nov 24 '15 at 12:55

2 Answers2

2

The documentation for distanceFromLocation: is quite clear:

This method measures the distance between the two locations by tracing a line between them that follows the curvature of the Earth. The resulting arc is a smooth curve and does not take into account specific altitude changes between the two locations.

Yes, this is the Great Circle Distance algorithm.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
0
+ (CGFloat)directMetersFromCoordinate:(CLLocationCoordinate2D)from toCoordinate:(CLLocationCoordinate2D)to {

static const double DEG_TO_RAD = 0.017453292519943295769236907684886;  
static const double EARTH_RADIUS_IN_METERS = 6372797.560856;  

double latitudeArc  = (from.latitude - to.latitude) * DEG_TO_RAD;
double longitudeArc = (from.longitude - to.longitude) * DEG_TO_RAD;
double latitudeH = sin(latitudeArc * 0.5);
latitudeH *= latitudeH;
double lontitudeH = sin(longitudeArc * 0.5);
lontitudeH *= lontitudeH;
double tmp = cos(from.latitude*DEG_TO_RAD) * cos(to.latitude*DEG_TO_RAD);
return EARTH_RADIUS_IN_METERS * 2.0 * asin(sqrt(latitudeH + tmp*lontitudeH));}

Source: Distance between two points on Globe

Dheeraj Jami
  • 190
  • 2
  • 14