| | |
| | | throw new RuntimeException("高德地图路径规划异常", e); |
| | | } |
| | | } |
| | | |
| | | public static JSONObject directionInfo(String mode, String from, String to) { |
| | | // 高德坐标系为 lng,lat |
| | | String[] fromArr = from.split(","); |
| | | String[] toArr = to.split(","); |
| | | String origin = fromArr[1] + "," + fromArr[0]; // lng,lat |
| | | String destination = toArr[1] + "," + toArr[0]; // lng,lat |
| | | |
| | | try { |
| | | String url; |
| | | if ("bicycling".equals(mode)) { |
| | | url = BICYCLING_URL |
| | | + "?key=" + amapKey |
| | | + "&origin=" + URLEncoder.encode(origin, "UTF-8") |
| | | + "&destination=" + URLEncoder.encode(destination, "UTF-8"); |
| | | } else { |
| | | // 默认驾车 |
| | | url = DRIVING_URL |
| | | + "?key=" + amapKey |
| | | + "&origin=" + URLEncoder.encode(origin, "UTF-8") |
| | | + "&destination=" + URLEncoder.encode(destination, "UTF-8"); |
| | | } |
| | | |
| | | log.info("高德地图路径规划请求: mode={}, from={}, to={}", mode, from, to); |
| | | |
| | | JSONObject json = new Http().build(url) |
| | | .setConnectTimeout(5000) |
| | | .setReadTimeout(10000) |
| | | .get() |
| | | .toJSONObject(); |
| | | |
| | | log.info("高德地图路径规划响应: {}", json); |
| | | return json; |
| | | } catch (IOException e) { |
| | | log.error("高德地图路径规划异常", e); |
| | | throw new RuntimeException("高德地图路径规划异常", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |