• 根据经纬度,获取两点间的距离



    public class LngLat {

    /**
    * 根据经纬度,获取两点间的距离
    *
    * @author zhijun.wu
    * @param lng1 经度
    * @param lat1 纬度
    * @param lng2
    * @param lat2
    * @return
    *
    * @date 2011-8-10
    */
    public static double distanceByLngLat(double lng1, double lat1, double lng2, double lat2) {
    double radLat1 = lat1 * Math.PI / 180;
    double radLat2 = lat2 * Math.PI / 180;
    double a = radLat1 - radLat2;
    double b = lng1 * Math.PI / 180 - lng2 * Math.PI / 180;
    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 * 6378137.0;// 取WGS84标准参考椭球中的地球长半径(单位:m)
    s = Math.round(s * 10000) / 10000;

    return s;
    }

    /**
    * 说明:
    *
    * @author zhijun.wu
    * @param args
    * @throws Exception
    *
    * @date 2008-5-16
    */
    public static void main(String[] args) throws Exception {
    System.out.println(distanceByLngLat(102.6592, 25.0751, 102.7655, 24.9525));
    }
    }


    /**
    * 计算两坐标的距离
    */
    public static int distance(double lat1, double lng1, double lat2,
    double lng2) {
    double dd = Math.PI / 180;
    double x1 = lat1 * dd, x2 = lat2 * dd;
    double y1 = lng1 * dd, y2 = lng2 * dd;
    double R = 6371004;//地球半径
    double distance = (2 * R * Math.asin(Math.sqrt(2 - 2 * Math.cos(x1)
    * Math.cos(x2) * Math.cos(y1 - y2) - 2 * Math.sin(x1)
    * Math.sin(x2)) / 2));
    // km 返回
    // return distance*1000;
    return (int) distance;
    }

  • 相关阅读:
    洛谷P2024 [NOI2001]食物链 题解 并查集
    洛谷P1632 点的移动 题解 枚举
    洛谷P2733 家的范围 题解 动态规划
    洛谷P1432 倒水问题 题解 广搜经典入门题(SPFA求解)
    18个常用的Linux 命令
    python 基础知正则表达式
    python 多功能下载网页
    Python3 安装urllib2包之小坑
    python 爬虫需要的库
    python html简单入门
  • 原文地址:https://www.cnblogs.com/jason-star/p/3656705.html
Copyright © 2020-2023  润新知