kaiyu
2021-09-30 eba6f1988c6a7e37e619a27e493b17c244979070
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.moral.util;
 
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;
 
import org.springframework.stereotype.Component;
 
@Component
public class GeodesyUtils {
    /**
     * @param lat1 第一点纬度
     * @param lng1 第一点经度
     * @param lat2 第二点纬度
     * @param lng2 第二点经度
     * @return 功能:根据经纬度计算两点间距离,采用WGS84坐标系
     */
    public static double getDistance(double lat1, double lng1, double lat2, double lng2) {
        GlobalCoordinates source = new GlobalCoordinates(lat1, lng1);
        GlobalCoordinates target = new GlobalCoordinates(lat2, lng2);
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.WGS84, source, target);
        return geoCurve.getEllipsoidalDistance();
    }
}