IcePoiSearchFTRClient.java 2.12 KB
package com.glsx.ice.iceClient;

import Ice.Communicator;
import com.glsx.ice.POI.IPOISearchFTRPrx;
import com.glsx.ice.POI.IPOISearchFTRPrxHelper;
import com.glsx.ice.POI.geocoding_result;
import com.glsx.ice.POI.geocoding_resultHolder;
import com.glsx.utils.SystemProperty;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class IcePoiSearchFTRClient {
    // ice接口服务器地址
    private static String ICE_URL = SystemProperty.getProperty("ice.poiSearchFTRUrl");
    static Communicator ic = Ice.Util.initialize();
    static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
    static IPOISearchFTRPrx ipoiSearchFTRPrx = IPOISearchFTRPrxHelper.checkedCast(base);

    /**
     * 通过逆地址解析
     *
     * @return
     */
    public static Map<String, Object> Geocoding(String address) {
        //请求和响应对象
        geocoding_resultHolder res = new geocoding_resultHolder();
        try {
            if (ipoiSearchFTRPrx == null) {
                log.error("mapGeoConvert ice添加服务异常 servicePre is null");
                return null;
            }
            ipoiSearchFTRPrx.Geocoding(address, res);

            Map<String, Object> map = null;
            if (res != null && res.value != null) {
                geocoding_result val = res.value;
                map = new HashMap<>();
                //POI层级 0~7
                map.put("level", val.level);
                //可信度,分度越高越可信
                map.put("confidence", val.confidence);
                //经度
                map.put("lng", val.pt.lng / 1000000D);
                //纬度
                map.put("lat", val.pt.lat / 1000000D);
                return map;
            }
        } catch (Ice.LocalException e) {
            log.error("Geocoding ice localexception" + e.getMessage(), e);
        } catch (Exception e) {
            log.error("Geocoding ice exception" + e.getMessage(), e);
        }
        log.info("Geocoding ice添加接口调用结束");
        return null;
    }
}