jiangping
2025-02-28 d7aaa1eae5335b38ba1e8e9a465ef9099bc334c5
server/services/src/main/java/com/doumee/core/utils/PositionUtil.java
@@ -1,6 +1,8 @@
package com.doumee.core.utils;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.doumee.dao.business.web.request.LocaltionDTO;
import java.awt.geom.GeneralPath;
@@ -13,7 +15,43 @@
 */
public class PositionUtil {
    /**
    public static String getTxMapAddrByLatAndLng(Double lat,Double lng,String host,String mapkey){
        try {
            if(lat == null || lng ==null){
                return null;
            }
            String url =host +"/ws/geocoder/v1/?key="+mapkey+"&location="+lat+","+lng;
            String res = HttpsUtil.get(url,false);
            JSONObject jsonObject = JSONObject.parseObject(res );
           String r = null;
           if(jsonObject.getJSONObject("result")!=null){
               if(jsonObject.getJSONObject("result").getJSONObject("formatted_addresses")!=null){
                   r =jsonObject.getJSONObject("result").getJSONObject("formatted_addresses").getString("formatted_addresses");
               }
               if(r!=null && !r.equals("")){
                   r =jsonObject.getJSONObject("result").getString("address");
               }
           }
           return r;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    public static void main(String[] args) {
        String str ="[{\"lat\": 31.71383446224521, \"lng\": 117.39342857107226, \"height\": 0}, {\"lat\": 31.71393087373135, \"lng\": 117.39402357524818, \"height\": 0}, {\"lat\": 31.713593433089077, \"lng\": 117.39433170240886, \"height\": 0}, {\"lat\": 31.713280450806966, \"lng\": 117.39358710879355, \"height\": 0}]";
        TypeReference typeReference =  new TypeReference<List<LocaltionDTO>>(){};
        List<LocaltionDTO> array = JSONObject.parseObject(str, typeReference.getType());
        if(array == null || array.size() ==0){
           System.out.println("=================");
        }
        System.out.println(isInPolygon(117.39, 31.71551600,array));
    }
   /* "latitude": 31.71551600,
            "longitude": 117.39,
   */ /**
     * 判断坐标点是否在多边形区域内
     *
     * @param pointLon 要判断的点的经度