admin
2021-11-19 7511509c68bd2892aad48a0612d497387660214d
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
26
27
28
29
30
31
32
33
34
35
package com.yeshi.location.app.utils;
 
import com.yeshi.location.app.entity.location.SimpleLocationInfo;
 
/**
 * @author hxh
 * @title: GeoUtils
 * @description: 地理工具类
 * @date 2021/11/19 18:31
 */
public class GeoUtils {
 
 
    /**
     * @return double
     * @author hxh
     * @description 获取两个坐标间的距离
     * @date 18:34 2021/11/19
     * @param: loc1
     * @param: loc2
     **/
    public static double getDistance(SimpleLocationInfo loc1, SimpleLocationInfo loc2) {
        double radlat1 = Math.toRadians(loc1.getLatitude().doubleValue());
        double radlat2 = Math.toRadians(loc2.getLatitude().doubleValue());
        double a = radlat1 - radlat2;
        double b = Math.toRadians(loc1.getLongitude().doubleValue()) - Math.toRadians(loc2.getLongitude().doubleValue());
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radlat1)
                * Math.cos(radlat2) * Math.pow(Math.sin(b / 2), 2)));
        s = s * 6378137.0;// 取wgs84标准参考椭球中的地球长半径(单位:m)
        s = Math.round(s * 10000) / 10000;
        return s;
    }
 
 
}