| | |
| | | * @return |
| | | */ |
| | | public Map<String, String> getDistance(String origins, String destination, Integer type){ |
| | | String url = "https://restapi.amap.com/v3/distance?key=" + key + "&origins=" + origins + "&destination=" + destination + |
| | | "&type=" + type; |
| | | String url = "https://api.map.baidu.com/directionlite/v1/driving?origin="+origins+"&destination="+destination+"&ak="+key; |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | | JSONObject jsonObject = JSON.parseObject(forObject); |
| | | System.err.println("获取距离"+jsonObject); |
| | | String status = jsonObject.getString("status"); |
| | | |
| | | // gdInterfaceService.saveData("https://restapi.amap.com/v3/distance", "查询两点间的距离"); |
| | | |
| | | if(status.equals("1")){ |
| | | JSONArray results = jsonObject.getJSONArray("results"); |
| | | if(status.equals("0")){ |
| | | JSONObject result = jsonObject.getJSONObject("result"); |
| | | JSONArray results = result.getJSONArray("routes"); |
| | | System.err.println("路线数组"+results); |
| | | JSONObject jsonObject1 = results.getJSONObject(0); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("distance", jsonObject1.getString("distance"));//距离(米) |
| | | map.put("duration", jsonObject1.getString("duration"));//预计时间(秒) |
| | | System.err.println("返回map"); |
| | | return map; |
| | | }else{ |
| | | System.err.println(forObject); |