IcePoiSearchNearClient.java 1.93 KB
package com.glsx.ice.iceClient;

import Ice.Communicator;
import Ice.StringHolder;
import com.glsx.ice.POI.IPOISearchNearPrx;
import com.glsx.ice.POI.IPOISearchNearPrxHelper;
import com.glsx.ice.POI.geopoint;
import com.glsx.utils.SystemProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Slf4j
public class IcePoiSearchNearClient {
    // ice接口服务器地址
    private static String ICE_URL = SystemProperty.getProperty("ice.poisearchUrl");
    static Communicator ic = Ice.Util.initialize();
    static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
    static IPOISearchNearPrx poiSearchNearPrx = IPOISearchNearPrxHelper.checkedCast(base);
    /**
     * 通过逆地址解析
     *
     * @param lat
     * @param lng
     * @return
     */
    public static String getReverseGeocoding(float lat, float lng) {
        //请求和响应对象
        geopoint ptCenterGeopoint = new geopoint();
        ptCenterGeopoint.lng = lng;
        ptCenterGeopoint.lat = lat;
        StringHolder poiSearchHolder = new StringHolder();
        try {
            if (poiSearchNearPrx == null) {
                log.error("mapGeoConvert ice添加服务异常 servicePre is null");
                return null;
            }
            int geoRes = poiSearchNearPrx.ReverseGeocoding(ptCenterGeopoint, poiSearchHolder);
            String value = poiSearchHolder.value;
            if (geoRes == 0 && value != null && !StringUtils.isEmpty(value)) {        // 结果为 0 表示调用成功
                return value;
            }
        } catch (Ice.LocalException e) {
            log.error("mapGeoConvert ice localexception" + e.getMessage(), e);
        } catch (Exception e) {
            log.error("mapGeoConvert ice exception" + e.getMessage(), e);
        }
        log.info("mapGeoConvert ice添加接口调用结束");
        return null;
    }
}