java 高德地图 车型比价计算_JAVA调用高德地图API实践

高德地图api接口文档地址:https://lbs.amap.com/api/

JAVA调用高德地图API,反解析中地址为经纬度。

/**

* 高德地图WebAPI : 地址转化为高德坐标

* String address:高德地图地址

* KEY-为地图key,这里的key要申请对应服务的key 一定要选择“web服务”项的key

* 输入:成都市武侯区

* 输出:104.043390,30.641982

*/

public static String coordinate(String address) {

try {

address = URLEncoder.encode(address, "utf-8");

} catch (UnsupportedEncodingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

String url = BASE_PATH + "/geocode/geo?address=" + address + "&output=json&key="+ KEY;

String coordinateString = null;

try {

String temp=HttpClientUtil.doGet(url);

JSONObject jsonobject = JSONObject.fromObject(temp);

JSONArray pathArray = jsonobject.getJSONArray("geocodes");

coordinateString = pathArray.getJSONObject(0).getString("location");

} catch (IOException e) {

e.printStackTrace();

}

return coordinateString;

}

计算两个经纬度之间的驾驶距离

/**

* 高德地图WebAPI : 驾车路径规划 计算两地之间行驶的距离(米)

* String origins:起始坐标

* String destination:终点坐标

*输入:原坐标:{116.45925,39.910031},目标坐标:{116.587922,40.081577}

*输出:25424

*/

public static String distance(String origins, String destination) {

String distanceString = null;

try {

String url = BASE_PATH + "/direction/driving?" + "origin=" + origins + "&destination=" + destination

+ "&output=json"+ "&key="+ KEY;

String aa =HttpClientUtil.doGet(url);

JSONObject jsonobject=JSONObject.fromObject(aa);

JSONArray pathArray = jsonobject.getJSONObject("route").getJSONArray("paths");

distanceString = pathArray.getJSONObject(0).getString("distance");

} catch (Exception e) {

e.printStackTrace();

}

return distanceString;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值