package com.izouma.dingdong.utils;

public class MapUtils {
    //地球半径
    private static final Double EARTH_RADIUS = 6378.137;

    /**
     * 计算距离
     *
     * @param longitude1 商家经度
     * @param latitude1  商家纬度
     * @param longitude2 当前经度
     * @param latitude2  当前纬度
     * @return 距离
     */
    public static Double distance(Double longitude1, Double latitude1, Double longitude2, Double latitude2) {
        double radLat1 = latitude1 * Math.PI / 180.0;
        double radLat2 = latitude2 * Math.PI / 180.0;
        double a = radLat1 - radLat2;
        double b = longitude1 * Math.PI / 180.0 - longitude2 * Math.PI / 180.0;

        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 * EARTH_RADIUS;
        s = Math.round(s * 1000);
        return s;
    }
}
