收藏
回答

用户发布定位获取返回经纬度坐标,与实际地图定位不匹配。怎么解决?

/**

 * 中文地址解析为经纬度

 *

 * @param address

 * @return

 */

public ResponseResult<RegeoModel> regeo(String address) {

    ResponseResult<RegeoModel> result = new ResponseResult<>();

    result.setStatus(-1);

    try {

        String url = "https://apis.map.qq.com/ws/geocoder/v1/?address=";

        URIBuilder urlBuilder = new URIBuilder(url);

        urlBuilder.addParameter("address", address);

        urlBuilder.addParameter("key", key);

        HttpGet httpGet = new HttpGet(urlBuilder.build());


        HttpResponse httpResponse = httpClient.execute(httpGet);

        if (validHttpStatusCode(httpResponse)) {

            result.setStatus(ResponseResult.status_success);

            String response = EntityUtils.toString(httpResponse.getEntity());

            logger.debug("", response);

            JSONObject map = JSONObject.parseObject(response);

            if (map.getInteger("status") == 0) {

                JSONObject resultData = map.getJSONObject("result");

                RegeoModel regeoModel = new RegeoModel();

                JSONObject location = resultData.getJSONObject("location");

                regeoModel.setLng(location.getBigDecimal("lng"));

                regeoModel.setLat(location.getBigDecimal("lat"));

                JSONObject addressComponents = resultData.getJSONObject("address_components");

                regeoModel.setProvince(addressComponents.getString("province"));

                regeoModel.setCity(addressComponents.getString("city"));

                regeoModel.setDistrict(addressComponents.getString("district"));

                regeoModel.setStreet(addressComponents.getString("street"));

                JSONObject adInfo = resultData.getJSONObject("ad_info");

                if (adInfo != null && adInfo.get("adcode") != null) {

                    regeoModel.setAdCode(adInfo.getString("adcode"));

                }

                result.setData(regeoModel);

                return result;

            } else {

                result.setStatus(map.getInteger("status"));

                lo

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容