| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String reverseGeocoding(double lng, double lat) { |
| | | //调用百度地址反向解析接口 |
| | | String url = "https://api.map.baidu.com/reverse_geocoding/v3/"; |
| | | String params = "location=" + lat + "," + lng + |
| | | "&output=json" + |
| | | "&ak=" + baiduMapConfig.getAk(); |
| | | String response = HttpUtils.sendGet(url, params); |
| | | //"{\"status\":0,\"result\":{\"location\":{\"lng\":113.25330399999999,\"lat\":23.04668300960378},\"formatted_address\":\"广东省佛山市南海区桂城街道\",\"edz\":{\"name\":\"\"},\"business\":\"\",\"business_info\":[],\"addressComponent\":{\"country\":\"中国\",\"country_code\":0,\"region_code_iso\":\"CHN\",\"country_code_iso\":\"CHN\",\"country_code_iso2\":\"CN\",\"province\":\"广东省\",\"city\":\"佛山市\",\"city_level\":2,\"district\":\"南海区\",\"town\":\"桂城街道\",\"town_code\":\"440605011\",\"distance\":\"\",\"direction\":\"\",\"adcode\":\"440605\",\"street\":\"\",\"street_number\":\"\"},\"pois\":[],\"roads\":[],\"poiRegions\":[],\"sematic_description\":\"\",\"formatted_address_poi\":\"\",\"cityCode\":138}}" |
| | | JSONObject jsonObject = JSONObject.parseObject(response); |
| | | if (jsonObject.getInteger("status") != 0) { |
| | | logger.warn("百度地图地址反向解析失败: lng={}, lat={}, status={}, message={}", |
| | | lng, lat, jsonObject.getInteger("status"), jsonObject.getString("message")); |
| | | return null; |
| | | } |
| | | String address = jsonObject.getJSONObject("result").getString("formatted_address"); |
| | | logger.info("百度地图地址反向解析成功: lng={}, lat={}, address={}", lng, lat, address); |
| | | return address; |
| | | } |
| | | } |