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;
|
}
|
|
|
}
|