| | |
| | | |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.xiaopeng.map.config.MapApiConfigHolder; |
| | | import com.xiaopeng.map.config.MapApiProperties; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpGet; |
| | |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | public class GaodeMapService { |
| | | |
| | | // 高德地图API基础URL |
| | | private static final String WALKING_API_URL = "https://restapi.amap.com/v3/direction/walking"; |
| | | |
| | | // 你的高德地图API Key |
| | | private String apiKey; |
| | | |
| | | public GaodeMapService(String apiKey) { |
| | | this.apiKey = apiKey; |
| | | |
| | | private final String walkingApiUrl; |
| | | |
| | | private final String apiKey; |
| | | |
| | | public GaodeMapService() { |
| | | MapApiProperties properties = MapApiConfigHolder.getProperties(); |
| | | this.walkingApiUrl = properties.getUrls().getWalking(); |
| | | this.apiKey = properties.getApiKey(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取步行路径规划 |
| | | * @param origin 起点坐标,格式:经度,纬度 |
| | |
| | | */ |
| | | private String buildWalkingUrl(String origin, String destination) { |
| | | return String.format("%s?origin=%s&destination=%s&key=%s", |
| | | WALKING_API_URL, |
| | | walkingApiUrl, |
| | | origin, |
| | | destination, |
| | | apiKey); |
| | |
| | | |
| | | return result; |
| | | } |
| | | } |
| | | } |