We need to pass to coordinate to the input to the system and the distance calculated and produced as as output NSNumber
- (NSNumber*)calculateDistanceInMetersBetweenCoord:(CLLocationCoordinate
2
D)coord
1
coord
:(CLLocationCoordinate
2
D)coord
2
{
NSInteger
nRadius =
6
3
7
1
;
// Earth's radius in Kilometers
double
latDiff = (coord
2
.latitude
- coord
1
.latitude
) * (M_PI/
1
8
0
);
double
lonDiff = (coord
2
.longitude
- coord
1
.longitude
) * (M_PI/
1
8
0
);
double
lat
1
InRadians = coord
1
.latitude
* (M_PI/
1
8
0
);
double
lat
2
InRadians = coord
2
.latitude
* (M_PI/
1
8
0
);
double
nA = pow ( sin(latDiff/
2
),
2
) + cos(lat
1
InRadians) * cos(lat
2
InRadians) * pow ( sin(lonDiff/
2
),
2
);
double
nC =
2
* atan
2
( sqrt(nA), sqrt(
1
- nA ));
double
nD =
nRadius
* nC;
// convert to meters
return
@(nD*
1
0
0
0
);
}
for further reference refer apple guide and here
No comments:
Post a Comment