Преглед изворни кода

根据坐标系计算距离

fllmoyu пре 4 година
родитељ
комит
13a68e8920

+ 6 - 0
common/pom.xml

@@ -254,6 +254,12 @@
             <artifactId>gps</artifactId>
             <version>1.0.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.gavaghan</groupId>
+            <artifactId>geodesy</artifactId>
+            <version>1.1.3</version>
+        </dependency>
     </dependencies>
 
 

+ 14 - 0
common/src/main/java/com/jpsoft/bus/modules/common/utils/CommonUtil.java

@@ -1,6 +1,10 @@
 package com.jpsoft.bus.modules.common.utils;
 
 import cn.hutool.core.util.StrUtil;
+import org.gavaghan.geodesy.Ellipsoid;
+import org.gavaghan.geodesy.GeodeticCalculator;
+import org.gavaghan.geodesy.GeodeticCurve;
+import org.gavaghan.geodesy.GlobalCoordinates;
 
 /**
  * @author 墨鱼_mo
@@ -109,4 +113,14 @@ public class CommonUtil {
 
         return provinceNum;
     }
+
+
+    //根据坐标系判断距离
+    public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid) {
+
+        //创建GeodeticCalculator,调用计算方法,传入坐标系、经纬度用于计算距离
+        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);
+
+        return geoCurve.getEllipsoidalDistance();
+    }
 }