zoukankan      html  css  js  c++  java
  • 知道两个点的经纬度计算两个点的距离

    经纬度首先转化为弧度

    然后使用公式即可

     1     private     static double EARTH_RADIUS=6378.137;
     2     private static double rad(double d) {
     3             return d*Math.PI/180.0;
     4     }
     5     public static double getDistance(double latitude1,double longitude1,double latitude2, double longitude2 ) {
     6         double distance=0;
     7         double radLatitude1=rad(latitude1);
     8         double radLatitude2=rad(latitude2);
     9         double dis1=radLatitude1-radLatitude2;
    10         double dis2=rad(longitude1)-rad(longitude2);
    11         distance=2*Math.asin(Math.sqrt(Math.pow(Math.sin(dis1/2), 2)+Math.cos(radLatitude1)*Math.cos(radLatitude2)*Math.pow(Math.sin(dis2/2), 2)));
    12         distance=distance*EARTH_RADIUS;
    13         distance=Math.round(distance*10000d)/10000d;
    14         distance=distance*1000;
    15         return distance;
    16     }
    17     public static double getDistance2(double x1,double y1,double x2,double y2 ) {
    18         double distance=0;
    19         distance=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    20         return distance;
    21     }
    22     

    万事走心 精益求美


  • 相关阅读:
    leetcode目录
    Windows下tuxedo配置
    实习总结
    n人比赛,可轮空,比赛轮数和场数
    Ubuntu中Eclipse安装与配置
    Lunix中文乱码解决方案
    tuxedo入门
    useradd和adduser的区别
    每个位上都是素数
    TUXEDO错误解决方案
  • 原文地址:https://www.cnblogs.com/kongchung/p/9914285.html
Copyright © 2011-2022 走看看