| | |
| | | * @param endLonLat 结束经纬度(目标经纬度) |
| | | * @return java.lang.Long 两个定位点之间的距离 |
| | | */ |
| | | public String getDistanceTOKilometer(String startLonLat, String endLonLat) { |
| | | public double getDistanceTOKilometer(String startLonLat, String endLonLat) { |
| | | try { |
| | | // 返回起始地startAddr与目的地endAddr之间的距离,单位:米 |
| | | Long result = new Long(0); |
| | |
| | | String queryResult = getResponse(queryUrl); |
| | | JSONObject job = JSONObject.parseObject(queryResult); |
| | | JSONArray ja = job.getJSONArray("results"); |
| | | if (ja.size() == 0){ |
| | | return 0.00; |
| | | } |
| | | JSONObject jobO = JSONObject.parseObject(ja.getString(0)); |
| | | result = Long.parseLong(jobO.get("distance").toString()); |
| | | double kilDis = (double) result / 1000; |
| | | DecimalFormat decimalFormat = new DecimalFormat("#.00"); |
| | | return decimalFormat.format(kilDis); |
| | | return (double) result / 1000; |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(); |
| | | } |