高德地图实时路况对接

上传人:平*** 文档编号:16014948 上传时间:2017-11-06 格式:DOC 页数:6 大小:51.97KB
返回 下载 相关 举报
高德地图实时路况对接_第1页
第1页 / 共6页
高德地图实时路况对接_第2页
第2页 / 共6页
高德地图实时路况对接_第3页
第3页 / 共6页
高德地图实时路况对接_第4页
第4页 / 共6页
高德地图实时路况对接_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《高德地图实时路况对接》由会员分享,可在线阅读,更多相关《高德地图实时路况对接(6页珍藏版)》请在金锄头文库上搜索。

1、import java.io.IOException;import java.io.UnsupportedEncodingException;import java.text.SimpleDateFormat;import mons.httpclient.HttpClient;import mons.httpclient.HttpException;import mons.httpclient.HttpMethod;import mons.httpclient.methods.GetMethod;import org.dom4j.Document;import org.dom4j.Docume

2、ntException;import org.dom4j.DocumentHelper;import org.dom4j.Element;import org.slf4j.Logger;import org.slf4j.LoggerFactory;/* 对接高德地图实时路况对接* author glf*/public class RealTimeTrafficUtil protected static final Logger LOG = LoggerFactory.getLogger(RealTimeTrafficUtil.class);SimpleDateFormat sdf = new

3、SimpleDateFormat(yyyy-MM-dd HH:mm:ss);/* 获取前方路况播 报* param lat 纬度* param lon 经度* param speed 速度* param heading 角度* return*/public String RealTimeTraffic(String lat, String lon, String speed, String heading) StringBuffer sb = new StringBuffer();try HttpClient httpClient = new HttpClient();String url =

4、 http:/ lat+ ,+ lon+ ,+ speed+ ,+ heading+ ;&flag=12&userName=*&pcode=MDAwMDAwMDA=;HttpMethod method = new GetMethod(url);byte data = null;try httpClient.executeMethod(method);data = method.getResponseBody();method.releaseConnection(); catch (HttpException e) e.printStackTrace(); catch (IOException

5、e) e.printStackTrace();Document doc = null;try String xml = new String(data, UTF-8);doc = DocumentHelper.parseText(xml); catch (DocumentException e) e.printStackTrace();LOG.error(parse xml error.); catch (UnsupportedEncodingException e) e.printStackTrace();Element rootElem = doc.getRootElement();if

6、(0).equals(rootElem.elementText(status) / 没有此路信息,不做 处理String description = rootElem.element(front).elementText(description);sb.append(description); catch (Exception e) return null;sb = jq(sb);return sb.toString();/* 获取矩形范 围内的实时 路况* param x1 左上角经度* param y1 左上角纬度* param x2 右下角经度* param y2 右下角纬度* retu

7、rn*/public StringBuffer rectangle(double x1, double y1 , double x2 , double y2) StringBuffer sb = new StringBuffer();try HttpClient httpClient = new HttpClient();String url = http:/ method = new GetMethod(url);byte data = null;try httpClient.executeMethod(method);data = method.getResponseBody();meth

8、od.releaseConnection(); catch (HttpException e) e.printStackTrace(); catch (IOException e) e.printStackTrace();Document doc = null;try String xml = new String(data, UTF-8);doc = DocumentHelper.parseText(xml); catch (DocumentException e) e.printStackTrace();LOG.error(parse xml error.); catch (Unsuppo

9、rtedEncodingException e) e.printStackTrace();Element rootElem = doc.getRootElement();String description = rootElem.elementText(description);sb.append(description); catch (Exception e) / sb = jq(sb);return sb;/* 获取圆 形内的实时路况* param x 中心点经度* param y 中心点纬度* return*/public StringBuffer circle(double x, d

10、ouble y) StringBuffer sb = new StringBuffer();try HttpClient httpClient = new HttpClient();String url = http:/ method = new GetMethod(url);byte data = null;try httpClient.executeMethod(method);data = method.getResponseBody();method.releaseConnection(); catch (HttpException e) e.printStackTrace(); ca

11、tch (IOException e) e.printStackTrace();Document doc = null;try String xml = new String(data, UTF-8);doc = DocumentHelper.parseText(xml); catch (DocumentException e) e.printStackTrace();LOG.error(parse xml error.); catch (UnsupportedEncodingException e) e.printStackTrace();Element rootElem = doc.getRootElement();String description = rootElem.elementText(description);sb.append(description); catch (Exception e) / sb = jq(sb);return sb;public static void main(String args) RealTimeTrafficUtil line = new RealTimeTrafficUtil();line.RealTimeTraffic(39.944078, 116.355343, 248.710000, 33.050000);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号