地图经纬度距离计算


  public static final double DEGREES_TO_RADIANS = Math.PI / 180.0;
  public static final double RADIANS_TO_DEGREES = 180.0 / Math.PI;
  //地球半径
  public static final double EARTH_MEAN_RADIUS_KM = 6371.009;
  //地球直径
  private static final double EARTH_MEAN_DIAMETER = EARTH_MEAN_RADIUS_KM * 2;

/***
   * 距离半径计算方式
   * @param latCenterRad  中心点经纬度
   * @param lonCenterRad
   * @param latVals  目标经纬度
   * @param lonVals
   * @return 两坐标的距离 单位千米
   */
  public static double doubleVal(double latCenterRad, double lonCenterRad, double latVals, double lonVals) {
    //计算经纬度
    double latRad = latVals * DEGREES_TO_RADIANS;
    double lonRad = lonVals * DEGREES_TO_RADIANS;

    //计算经纬度的差
    double diffX = latCenterRad * DEGREES_TO_RADIANS - latRad;
    double diffY = lonCenterRad * DEGREES_TO_RADIANS - lonRad;
    //计算正弦和余弦
    double hsinX = Math.sin(diffX * 0.5);
    double hsinY = Math.sin(diffY * 0.5);
    double latCenterRad_cos = Math.cos(latCenterRad * DEGREES_TO_RADIANS);
    double h = hsinX * hsinX
            + (latCenterRad_cos * Math.cos(latRad) * hsinY * hsinY);

    return (EARTH_MEAN_DIAMETER * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)));
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值