根据经纬度查询附近

package com.yuezhu.utils;
/**
 * 根据经纬度查询附近
 * Created by 59238 on 2018/7/12.
 */
public class DegreeUtils {
    private static final  double EARTH_RADIUS = 6378137.0;//地球半径(米)

    // 角度数转换为弧度公式
    private static double radians(double d) {
        return d * Math.PI / 180.0;
    }

    // 弧度转换为角度数公式
    private static double degrees(double d) {
        return d * (180 / Math.PI);
    }
    // 计算两个经纬度之间的直接距离(google 算法)
    public static double GetDistanceGoogle(Double longitude, Double latitude,Double longitude2,Double latitude2) {
        double radLat1 = radians(longitude);
        double radLng1 = radians(latitude);
        double radLat2 = radians(longitude2);
        double radLng2 = radians(latitude2);

        double s = Math.acos(Math.cos(radLat1) * Math.cos(radLat2) * Math.cos(radLng1 - radLng2) + Math.sin(radLat1) * Math.sin(radLat2));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        return s;
    }

}

猜你喜欢

转载自blog.csdn.net/weixin_39643007/article/details/82081392