iOS 地图 通过经纬度计算两点间距离
- (double)calculateStart:(CLLocationCoordinate2D)start end:(CLLocationCoordinate2D)end { double meter = 0; double startLongitude = start.longitude; double startLatitude = start.latitude; double endLongitude = end.longitude; double endLatitude = end.latitude; double radLatitude1 = startLatitude * M_PI / 180.0; double radLatitude2 = endLatitude * M_PI / 180.0; double a = fabs(radLatitude1 - radLatitude2); double b = fabs(startLongitude * M_PI / 180.0 - endLongitude * M_PI / 180.0); double s = 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; //返回距离单位是米 return meter; }
//赤道半径
EARTH_RADIUS = 6378137;
//start 起点经纬度,数据格式 start = {lon:,lat:}
//end 终点定位度,数据格式 end = {lon:,lat:}
posted on 2015-06-04 11:44 bibibi_liuliu 阅读(648) 评论(0) 编辑 收藏 举报