欢迎来到天天文库
浏览记录
ID:33471988
大小:51.00 KB
页数:6页
时间:2019-02-26
《高德地图实时路况对接》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、importjava.io.IOException;importjava.io.UnsupportedEncodingException;importjava.text.SimpleDateFormat;importorg.apache.commons.httpclient.HttpClient;importorg.apache.commons.httpclient.HttpException;importorg.apache.commons.httpclient.HttpMethod;importorg
2、.apache.commons.httpclient.methods.GetMethod;importorg.dom4j.Document;importorg.dom4j.DocumentException;importorg.dom4j.DocumentHelper;importorg.dom4j.Element;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;/***对接高德地图实时路况对接*@authorglf**/publicclassRe
3、alTimeTrafficUtil{protectedstaticfinalLoggerLOG=LoggerFactory.getLogger(RealTimeTrafficUtil.class);SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");/***获取前方路况播报*@paramlat纬度*@paramlon经度*@paramspeed速度*@paramheading角度*@return*/publicStringRealTi
4、meTraffic(Stringlat,Stringlon,Stringspeed,Stringheading){StringBuffersb=newStringBuffer();try{HttpClienthttpClient=newHttpClient();Stringurl="http://online.mapabc.com/traffic?config=trafficinfo&datatype=0&gpsdata="+lat+","+lon+","+speed+","+heading+";&fla
5、g=12&userName=****&pcode=MDAwMDAwMDA=";HttpMethodmethod=newGetMethod(url);byte[]data=null;try{httpClient.executeMethod(method);data=method.getResponseBody();method.releaseConnection();}catch(HttpExceptione){e.printStackTrace();}catch(IOExceptione){e.print
6、StackTrace();}Documentdoc=null;try{Stringxml=newString(data,"UTF-8");doc=DocumentHelper.parseText(xml);}catch(DocumentExceptione){e.printStackTrace();LOG.error("parsexmlerror.");}catch(UnsupportedEncodingExceptione){e.printStackTrace();}ElementrootElem=do
7、c.getRootElement();if(("0").equals(rootElem.elementText("status"))){//没有此路信息,不做处理Stringdescription=rootElem.element("front").elementText("description");sb.append(description);}}catch(Exceptione){returnnull;}sb=jq(sb);returnsb.toString();}/***获取矩形范围内的实时路况*
8、@paramx1左上角经度*@paramy1左上角纬度*@paramx2右下角经度*@paramy2右下角纬度*@return*/publicStringBufferrectangle(doublex1,doubley1,doublex2,doubley2){StringBuffersb=newStringBuffer();try{HttpClienthttpClient=newHttpClient();Stringurl="
此文档下载收益归作者所有