根据一个坐标点获取距离3公里最大、最小的经度和维度

 
   
getCoordinateRange(lat, lng) {
      let that = this;
      const distance = 3;  // 3公里
      const radLatitude = that.degreesToRadians(lat);
      const radLongitude = that.degreesToRadians(lng);
      const radDistance = distance / 6371;

      // 计算圆的边界经纬度
      const minLatitude = radLatitude - radDistance;
      const maxLatitude = radLatitude + radDistance;
      const minLongitude = radLongitude - Math.asin(Math.sin(radDistance) / Math.cos(radLatitude));
      const maxLongitude = radLongitude + Math.asin(Math.sin(radDistance) / Math.cos(radLatitude));

      // 将其转换为角度并输出结果
      const minLatitudeDeg = minLatitude * 180 / Math.PI;
      const maxLatitudeDeg = maxLatitude * 180 / Math.PI;
      const minLongitudeDeg = minLongitude * 180 / Math.PI;
      const maxLongitudeDeg = maxLongitude * 180 / Math.PI;
    
}

degreesToRadians(degrees) {
      return degrees * Math.PI / 180;
},

你可能感兴趣的:(javascript,前端,算法)