zoukankan      html  css  js  c++  java
  • Java 根据两个经纬度,得到两点距离


    private static final double EARTH_RADIUS = 6371000;//赤道半径(单位m)
    private static final double INTEGR_NUM = 10000;

    /**
    * 基于googleMap中的算法得到两经纬度之间的距离,误差 <= 0.2m
    * @param lat1 第一点的精度
    * @param lng1 第一点的纬度
    * @param lat2 第二点的精度
    * @param lng2 第二点的纬度
    * @return 返回的距离,单位m
    * */

    public static double distance(double lat1, double lng1, double lat2, double lng2) {
    double x1 = Math.cos(lat1) * Math.cos(lng1);
    double y1 = Math.cos(lat1) * Math.sin(lng1);
    double z1 = Math.sin(lat1);
    double x2 = Math.cos(lat2) * Math.cos(lng2);
    double y2 = Math.cos(lat2) * Math.sin(lng2);
    double z2 = Math.sin(lat2);
    double lineDistance =
    Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
    double s = EARTH_RADIUS * Math.PI * 2 * Math.asin(0.5 * lineDistance) / 180;
    return Math.round(s * INTEGR_NUM) / INTEGR_NUM;
    }

  • 相关阅读:
    react方法传参的两种方式
    react引入本地图片和远程图片
    用yarn代替npm
    react生命周期
    react子传父
    react删除元素
    react遍历数组
    react监听input框里的值
    react创建组件的两种方式
    vue打包更改dist文件夹名称
  • 原文地址:https://www.cnblogs.com/Soy-technology/p/10980807.html
Copyright © 2011-2022 走看看