iOS开发 根据两点的经纬度计算两点真实距离

根据两点的经纬度计算两点真实距离

- (double)calculateStart:(CLLocationCoordinate2D)start end:(CLLocationCoordinate2D)end {

doubleEARTH_RADIUS =6378137;

doublemeter =0;

doublestartLongitude = start.longitude;

doublestartLatitude = start.latitude;

doubleendLongitude = end.longitude;

doubleendLatitude = end.latitude;

doubleradLatitude1 = startLatitude *M_PI/180.0;

doubleradLatitude2 = endLatitude *M_PI/180.0;

doublea =fabs(radLatitude1 - radLatitude2);

doubleb =fabs(startLongitude *M_PI/180.0- endLongitude *M_PI/180.0);

doubles =2*asin(sqrt(pow(sin(a/2),2) +cos(radLatitude1) *cos(radLatitude2) *pow(sin(b/2),2)));

s = s * EARTH_RADIUS;

meter =round(s *10000) /10000;//返回距离单位是米

returnmeter;

}

你可能感兴趣的:(iOS开发 根据两点的经纬度计算两点真实距离)