935090232@qq.com
2022-04-20 dc88fd134d48713f0e941ffb5af2d7ce2d475ed7
Merge branch 'developer'
2 files modified
17 ■■■■■ changed files
zq-erp/src/main/java/com/matrix/system/common/tools/LocationUtil.java 9 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/YuyueAction.java 8 ●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/common/tools/LocationUtil.java
@@ -1,5 +1,7 @@
package com.matrix.system.common.tools;
import java.math.BigDecimal;
public class LocationUtil {
    private static final double EARTH_RADIUS = 6378.137;
@@ -17,7 +19,7 @@
     *  shopX 店铺位置经度
     *  shopY  店铺位置纬度
     */
    public static double getDistance(double locX, double locY, double shopX, double shopY) {
    public static BigDecimal getDistance(double locX, double locY, double shopX, double shopY) {
        double a, b, d, sa2, sb2;
        locY = rad(locY);
        shopY = rad(shopY);
@@ -29,12 +31,13 @@
        d = 2   * EARTH_RADIUS
                * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(locY)
                * Math.cos(shopY) * sb2 * sb2));
        return d;
        return BigDecimal.valueOf(d);
    }
    public static void main(String[] args) {
        // 112.886891,28.222562,114.061937,22.626003  -- 634093.3209722887
        // 113.930692,22.939454 -- 597367.3546527711
        System.out.println(getDistance(112.886891d, 28.222562d, 113.930692, 22.939454));
//        System.out.println(getDistance(112.886891d, 28.222562d, 113.930692, 22.939454));
        System.out.println(BigDecimal.ONE.compareTo(BigDecimal.ZERO)>0);
    }
}
zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/YuyueAction.java
@@ -122,7 +122,7 @@
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, shopList);
        }
        Double distance = null;
        BigDecimal distance = null;
        SysShopInfo nearestShop = null;
        AjaxResult ajaxResult = new AjaxResult("200", shopList);
@@ -130,9 +130,9 @@
            for (SysShopInfo shopInfo : shopList) {
                Double shopX = Double.parseDouble(shopInfo.getLongitude());
                Double shopY = Double.parseDouble(shopInfo.getLatitude());
                Double disResult = LocationUtil.getDistance(Double.parseDouble(locX), Double.parseDouble(locY), shopX, shopY);
                shopInfo.setDistance(new BigDecimal(disResult).setScale(1, BigDecimal.ROUND_HALF_UP));
                if (distance == null || distance > disResult) {
                BigDecimal disResult = LocationUtil.getDistance(Double.parseDouble(locX), Double.parseDouble(locY), shopX, shopY);
                shopInfo.setDistance(disResult);
                if (distance == null || distance.compareTo(disResult)>0) {
                    distance = disResult;
                    nearestShop = shopInfo;
                }