用百度地图api计算两个地方的距离
来源:互联网 发布:15寸mac魔兽世界 编辑:程序博客网 时间:2024/05/16 23:50
/** * @author 距离计算 * */public class DistanceUtil {private static final String showLocationUrl = "http://api.map.baidu.com/geocoder/v2/?output=json&ak=RguGdBfvanKG10lrLHtUAtka&address=";private static final String waypointsDistanceUrl = "http://api.map.baidu.com/telematics/v3/distance?output=json&ak=RguGdBfvanKG10lrLHtUAtka&waypoints=";@SuppressWarnings("unchecked")public static Double twoCitysDistance(String startCityName, String endCityName){Double distance = 0.00;Map<String, Object> startShowLocation = JsoupTool.getJson(showLocationUrl+startCityName, null);Map<String, Object> startResultLocation = (Map<String, Object>) startShowLocation.get("result");Map<String, Object> startLocation = (Map<String, Object>) startResultLocation.get("location");String startLng = startLocation.get("lng").toString();String startLat = startLocation.get("lat").toString();Map<String, Object> showLocation = JsoupTool.getJson(showLocationUrl+endCityName, null);Map<String, Object> endResultLocation = (Map<String, Object>) showLocation.get("result");Map<String, Object> endLocation = (Map<String, Object>) endResultLocation.get("location");String endLng = endLocation.get("lng").toString();String endLat = endLocation.get("lat").toString();String showWaypointsDistanceUrl = waypointsDistanceUrl+startLng+","+startLat+";"+endLng+","+endLat;Map<String, Object> waypointsDistance = JsoupTool.getJson(showWaypointsDistanceUrl, null);String distanceStr = waypointsDistance.get("results").toString();distanceStr = distanceStr.replaceAll("\\[", "").replaceAll("\\]", "");String[] distanceArray = distanceStr.split(","); distance = Double.valueOf(distanceArray[0]);return distance;}@SuppressWarnings("unchecked")public static void main(String[] args) {String startCityName = "河南省郑州市市辖区";String endCityName = "河南省许昌市市辖区";System.out.println(showLocationUrl+startCityName);Map<String, Object> startShowLocation = JsoupTool.getJson(showLocationUrl+startCityName, null);Map<String, Object> startResultLocation = (Map<String, Object>) startShowLocation.get("result");Map<String, Object> startLocation = (Map<String, Object>) startResultLocation.get("location");String startLng = startLocation.get("lng").toString();String startLat = startLocation.get("lat").toString();Map<String, Object> showLocation = JsoupTool.getJson(showLocationUrl+endCityName, null);Map<String, Object> endResultLocation = (Map<String, Object>) showLocation.get("result");Map<String, Object> endLocation = (Map<String, Object>) endResultLocation.get("location");String endLng = endLocation.get("lng").toString();String endLat = endLocation.get("lat").toString();String showWaypointsDistanceUrl = waypointsDistanceUrl+startLng+","+startLat+";"+endLng+","+endLat;Map<String, Object> waypointsDistance = JsoupTool.getJson(showWaypointsDistanceUrl, null);String distanceStr = waypointsDistance.get("results").toString();distanceStr = distanceStr.replaceAll("\\[", "").replaceAll("\\]", "");String[] distanceArray = distanceStr.split(","); Double double1 = Double.valueOf(distanceArray[0]);System.out.println(new java.text.DecimalFormat("#").format(double1/1000/90));}}
阅读全文
1 0
- 用百度地图api计算两个地方的距离
- 在百度地图API开发中已知两个点之间的经纬度坐标计算其距离
- 在百度地图API开发中已知两个点之间的经纬度坐标计算其距离
- 根据两个百度地图坐标计算两点的距离
- mysql数据库中计算两个百度地图坐标的距离
- iOS 百度地图计算两个点时间的距离
- OC-百度地图计算两个坐标之间的距离
- 百度地图API计算俩点距离
- 用百度地图API获取的经纬度信息计算两点距离(Mysql函数)
- 百度地图距离计算,计算结果和调用百度的api一样
- 百度地图计算距离
- 百度地图计算两点之间的距离
- 基于百度地图api的移动路径绘制以及距离计算
- 百度地图api 实例 整个自动提示 并计算两地的行驶距离
- 百度地图api 实例 整个自动提示 并计算两地的行驶距离
- 百度地图api 实例 整个自动提示 并计算两地的行驶距离
- 百度地图api两地距离
- 百度地图坐标距离计算,源于百度地图JS API 2.0
- 【LeetCode】 53. Maximum Subarray 最大子序列和
- LSM树(Log-Structured Merge Tree)存储引擎
- WINDOWS10环境下apache2.4+php5.6.30(nts)+mysql5.7- web server环境手动配置
- Node.js 文件系统
- 欢迎使用CSDN-markdown编辑器
- 用百度地图api计算两个地方的距离
- Copy List with Random Pointer
- [leetcode]538. Convert BST to Greater Tree
- Leetcode053--找到分支最小路径和
- C++笔试题
- 每天一个 Linux 命令(41):ps命令
- C++中的inline关键字用法介绍
- (转)(笔记)screen tearing
- 宏定义函数和普通函数