| New file |
| | |
| | | package com.xiaopeng.order.utils; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.common.core.utils.HttpUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 高德地图的地理编码工具类 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | @Lazy |
| | | public class GDMapGeocodingUtil { |
| | | |
| | | private String key = "66ae577f63898dae3016d599fda57221"; |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String url = "https://tsapi.amap.com/v1/route/price?key=" + "66ae577f63898dae3016d599fda57221" + "&extensions=all&start=" +"113.384932" + "," + "23.155455"; |
| | | HashMap<String, Object> params = new HashMap<>(); |
| | | params.put("extensions", "all"); |
| | | params.put("start", "113.384932" + "," + "23.155455"); |
| | | params.put("end", "113.388209" + "," + "23.163455"); |
| | | params.put("routeUserType",2); |
| | | log.info("高德地图接口:{}", url); |
| | | log.info("高德地图参数:{}", params); |
| | | String post = HttpUtils.post(url, JSON.toJSONString(params)); |
| | | log.info("高德地图返回结果:"+ post); |
| | | JSONObject jsonObject = JSON.parseObject(post); |
| | | System.out.println(jsonObject); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 线路还原接口 |
| | | * 车端使用的数据 |
| | | * @param routeID |
| | | * @return |
| | | */ |
| | | public String routed(String routeID){ |
| | | String url = "https://tsapi.amap.com/v1/route/query/routeid?key=" + key; |
| | | HashMap<String, Object> params = new HashMap<>(); |
| | | params.put("routeID", routeID); |
| | | params.put("sdkVersion", "9.850.152.3.532"); |
| | | params.put("encoderVersion", "5.1"); |
| | | String post = HttpUtils.post(url, JSON.toJSONString(params)); |
| | | log.info("高德地图返回结果:"+ post); |
| | | return post; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据经纬度获取行政区域信息 |
| | | * @param lon |
| | | * @param lan |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public Map<String, String> geocode(String lon, String lan) { |
| | | String url = "https://restapi.amap.com/v3/geocode/regeo?key=" + key + "&location=" + lon + "," + lan; |
| | | String forObject = HttpUtils.sendGet(url); |
| | | JSONObject jsonObject = JSON.parseObject(forObject); |
| | | Map<String, String> map = new HashMap<>(); |
| | | if(jsonObject.getString("status").equals("1")){ |
| | | JSONObject regeocode = jsonObject.getJSONObject("regeocode"); |
| | | JSONObject addressComponent = regeocode.getJSONObject("addressComponent"); |
| | | String address = regeocode.getString("formatted_address"); |
| | | map.put("address", address); |
| | | String code = addressComponent.getString("adcode"); |
| | | String province = addressComponent.getString("province"); |
| | | String city = addressComponent.getString("city"); |
| | | String district = addressComponent.getString("district"); |
| | | map.put("province", province); |
| | | map.put("provinceCode", code.substring(0, 2) + "0000"); |
| | | map.put("city", city); |
| | | map.put("cityCode", code.substring(0, 4) + "00"); |
| | | map.put("district", district); |
| | | map.put("districtCode", code); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | } |