计算两个经纬度点的实际距离

一、概述

因为地球是个球形,所以地球上的两个点,实际上是球面上的两个点,要计算这两个点之间的距离,不能简单的通过直角坐标系来计算。

 

二、计算方法

1、地球半径取近似值 6378.137km

1 /**
2      * 地球半径
3      * 6378.137km
4      */
5     public static final double EARTH_RADIUS = 6.371229*1e6;

2、实现代码

 1 /**
 2      * 求地球两点距离
 3      * @param sLat
 4      * @param sLng
 5      * @param eLat
 6      * @param eLng
 7      * @return
 8      */
 9     public static double latitudeLongitudeDistEarth(double sLat, double sLng, double eLat, double eLng)
10     {
11         double x,y,out;
12         double PI=Math.PI;
13 
14         x=(eLat-sLat)* PI * ExecutorConstant.EARTH_RADIUS * Math.cos( ((sLng+eLng)/2) * PI /180)/180;
15         y=(eLng-sLng)* PI * ExecutorConstant.EARTH_RADIUS /180;
16         out=Math.hypot(x,y);
17         return out;
18     }

以上只给出了公式,并没有详细的原理,仅供参考

参考资料:

http://mathforum.org/library/drmath/view/51879.html

http://blog.charlee.li/location-search/

http://www.cnblogs.com/softfair/p/distance_of_two_latitude_and_longitude_points.html

转载于:https://www.cnblogs.com/andy0810/p/10074957.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值