lbs距离计算

2021-12-16 14:27  557人阅读  评论 (0)
Tags: lbs

lbs中计算连个坐标的距离

function distance(lat1, lng1, lat2, lng2) { 
  const toRadians = d => d * Math.PI / 180;
  const radLat1 = toRadians(lat1);
  const radLat2 = toRadians(lat2);
  const deltaLat = radLat1 - radLat2;
  const deltaLng = toRadians(lng1) - toRadians(lng2);
  return 6378137 * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));
}





豫ICP备09035262号-1