计算两个坐标点之间的距离

 
//在网上找的,所说是谷歌的算法,我把参数和返回值的单位改了,传入经纬度的毫秒,返回距离毫米

public class Maps {
 private static  double EARTH_RADIUS = 6378.137;
 private static double rad(double d)
 {
    return d * Math.PI / 180.0;
 }

 public static int GetDistance(int lat1, int lng1, int lat2, int lng2)
 {
    double radLat1 = rad(lat1/3600000d);
    double radLat2 = rad(lat2/3600000d);
    double a = radLat1 - radLat2;
    double b = rad(lng1/3600000d) - rad(lng2/3600000d);
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) + 
     Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
    s = s * EARTH_RADIUS;
    s = Math.round(s * 1000*100*10) ;
    return (int) s;
 } 
 public static void main(String[] args) {
  System.out.println(Maps.GetDistance(115323149,  427590821, 115411079, 427564354));
 }
}

另,

毫妙和度之间是360万(3600000)的关系 1度=3600000毫秒

你可能感兴趣的:(java)