Java根據(jù)坐標(biāo)經(jīng)緯度計算兩點(diǎn)距離(5種方法)、校驗經(jīng)緯度是否在圓 多邊形區(qū)域內(nèi)的算法推薦 | 您所在的位置:網(wǎng)站首頁 › 屬兔的男寶寶名字大全 › Java根據(jù)坐標(biāo)經(jīng)緯度計算兩點(diǎn)距離(5種方法)、校驗經(jīng)緯度是否在圓 多邊形區(qū)域內(nèi)的算法推薦 |
@return 返回的距離,單位m */ public static double getDistance3(double longitude1, double latitude1, double longitude2, double latitude2) { // 經(jīng)緯度(角度)轉(zhuǎn)弧度。弧度作為作參數(shù),用以調(diào)用Math.cos和Math.sin // A經(jīng)弧度 double radiansAX = Math.toRadians(longitude1); // A緯弧度 double radiansAY = Math.toRadians(latitude1); // B經(jīng)弧度 double radiansBX = Math.toRadians(longitude2); // B緯弧度 double radiansBY = Math.toRadians(latitude2); // 公式中“cosβ1cosβ2cos(α1-α2)+sinβ1sinβ2”的部分,得到∠AOB的cos值 double cos = Math.cos(radiansAY) * Math.cos(radiansBY) * Math.cos(radiansAX - radiansBX) + Math.sin(radiansAY) * Math.sin(radiansBY); // System.out.println("cos = " + cos); // 值域[-1,1] // 反余弦值 double acos = Math.acos(cos); // System.out.println("acos = " + acos); // 值域[0,π] // System.out.println("∠AOB = " + Math.toDegrees(acos)); // 球心角 值域[0,180] // 最終結(jié)果 return EARTH_AVG_RADIUS * acos; } |
CopyRight 2018-2019 實驗室設(shè)備網(wǎng) 版權(quán)所有 |