We need to pass to coordinate to the input to the system and the distance calculated and produced as as output NSNumber
- (NSNumber*)calculateDistanceInMetersBetweenCoord:(CLLocationCoordinate2D)coord1coord:(CLLocationCoordinate2D)coord2{NSIntegernRadius =6371;// Earth's radius in KilometersdoublelatDiff = (coord2.latitude- coord1.latitude) * (M_PI/180);doublelonDiff = (coord2.longitude- coord1.longitude) * (M_PI/180);doublelat1InRadians = coord1.latitude* (M_PI/180);doublelat2InRadians = coord2.latitude* (M_PI/180);doublenA = pow ( sin(latDiff/2),2) + cos(lat1InRadians) * cos(lat2InRadians) * pow ( sin(lonDiff/2),2);doublenC =2* atan2( sqrt(nA), sqrt(1- nA ));doublenD =nRadius* nC;// convert to metersreturn@(nD*1000);}
for further reference refer apple guide and here
No comments:
Post a Comment