| | |
| | | /** |
| | | * 功能描述: 高德地图Key |
| | | */ |
| | | private static final String GAO_DE_KEY = "37331f325a4f4ea25bc0d4e1900a1730"; |
| | | private static final String GAO_DE_KEY = "2f22a10b75e0c24a074de515f3cdcaea"; |
| | | |
| | | /** |
| | | * 功能描述: 根据地址名称得到两个地址间的距离 |
| | |
| | | * @return 两个定位点之间的距离 |
| | | */ |
| | | public static Result<Long> getDistance(String startLonLat, String endLonLat) { |
| | | System.err.println("======"+startLonLat+"===="+endLonLat); |
| | | // 返回起始地startAddr与目的地endAddr之间的距离,单位:米 |
| | | String queryUrl = |
| | | "http://restapi.amap.com/v3/distance?key=" + GAO_DE_KEY + "&origins=" + startLonLat |
| | | + "&destination=" |
| | | + endLonLat; |
| | | String queryResult = getResponse(queryUrl); |
| | | System.err.println("======"+queryResult); |
| | | JSONObject job = JSONObject.parseObject(queryResult); |
| | | JSONArray ja = job.getJSONArray("results"); |
| | | JSONObject jobO = JSONObject.parseObject(ja.getString(0)); |
| | |
| | | public static Result<CityInfoVO> getAddressInfo(String address) { |
| | | // 返回起始地startAddr与目的地endAddr之间的距离,单位:米 |
| | | String queryUrl = "https://restapi.amap.com/v3/geocode/geo?address=" + address |
| | | + "&key=" + GAO_DE_KEY; |
| | | + "&output=json&key=" + GAO_DE_KEY; |
| | | String queryResult = getResponse(queryUrl); |
| | | GaoDeAddressInfoVO data = JSONObject.parseObject(queryResult, GaoDeAddressInfoVO.class); |
| | | List<Geocodes> geocodes = data.getGeocodes(); |
| | | if (geocodes==null||geocodes.isEmpty()) |
| | | return Result.failed(null, "计算失败"); |
| | | Geocodes info = geocodes.get(0); |
| | | String adcode = info.getAdcode(); |
| | | String city = info.getCity(); |
| | | return Result.succeed(new CityInfoVO(city, adcode), "距离计算成功!"); |
| | | String location = info.getLocation(); |
| | | String[] split = location.split(","); |
| | | return Result.succeed(new CityInfoVO(city, adcode,Double.valueOf(split[0]),Double.valueOf(split[1])), "距离计算成功!"); |
| | | } |
| | | |
| | | /** |