zoukankan      html  css  js  c++  java
  • 根据地球上两个坐标点,计算出距离

    public class MapDistance {


     private final static double PI = 3.14159265358979323; // 圆周率
     private final static double R = 6371229; // 地球的半径

     public static double getDistance(double longt1, double lat1, double longt2,
       double lat2) {
      double x, y, distance;
      x = (longt2 - longt1) * PI * R
        * Math.cos(((lat1 + lat2) / 2) * PI / 180) / 180;
      y = (lat2 - lat1) * PI * R / 180;
      //System.out.println((Math.hypot(x, y) / 1000));
      //distance = Double.parseDouble(String.format("%.0f", Math.hypot(x, y) / 1000));
      distance = (Math.hypot(x, y) / 1000);
      return distance;
     }

     public static void main(String[] args) {
     
      System.out.println(getDistance(40.137004,116.394765, 116.337795,39.977523));
     }
     
    }

  • 相关阅读:
    HTTP报文详解
    常用的HTTP协议
    URL详解
    一起切磋
    emacs使用指南
    SSH自动部署
    linux上应用随机启动
    让Maven正确处理javac警告
    最近的学习
    Java application 性能分析分享
  • 原文地址:https://www.cnblogs.com/MyBeN/p/4118904.html
Copyright © 2011-2022 走看看