java 判断两个经纬度差异_计算两个经纬度点的实际距离
一、概述
因?yàn)榈厍蚴莻€(gè)球形,所以地球上的兩個(gè)點(diǎn),實(shí)際上是球面上的兩個(gè)點(diǎn),要計(jì)算這兩個(gè)點(diǎn)之間的距離,不能簡(jiǎn)單的通過直角坐標(biāo)系來計(jì)算。
二、計(jì)算方法
1、地球半徑取近似值 6378.137km
1 /**
2 * 地球半徑
3 * 6378.137km
4 */
5 public static final double earth_radius = 6.371229*1e6;
2、實(shí)現(xiàn)代碼
1 /**
2 * 求地球兩點(diǎn)距離
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 }
以上只給出了公式,并沒有詳細(xì)的原理,僅供參考
參考資料:
希望與廣大網(wǎng)友互動(dòng)??
點(diǎn)此進(jìn)行留言吧!
總結(jié)
以上是生活随笔為你收集整理的java 判断两个经纬度差异_计算两个经纬度点的实际距离的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Excel介绍
- 下一篇: Apache ZooKeeper【动物管