欢迎来到天天文库
浏览记录
ID:1394068
大小:51.00 KB
页数:6页
时间:2017-11-11
《高德地图实时路况对接》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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.apache.commons
2、.httpclient.methods.GetMethod;importorg.dom4j.Document;importorg.dom4j.DocumentException;importorg.dom4j.DocumentHelper;importorg.dom4j.Element;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;/***对接高德地图实时路况对接*@authorglf**/publicclassRealTimeTrafficUtil{protectedsta
3、ticfinalLoggerLOG=LoggerFactory.getLogger(RealTimeTrafficUtil.class);SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");/***获取前方路况播报*@paramlat纬度*@paramlon经度*@paramspeed速度*@paramheading角度*@return*/publicStringRealTimeTraffic(Stringlat,Stringlon,Stringspeed,Str
4、ingheading){StringBuffersb=newStringBuffer();try{HttpClienthttpClient=newHttpClient();Stringurl="http://online.mapabc.com/traffic?config=trafficinfo&datatype=0&gpsdata="+lat+","+lon+","+speed+","+heading+";&flag=12&userName=****&pcode=MDAwMDAwMDA=";HttpMethodmethod=newG
5、etMethod(url);byte[]data=null;try{httpClient.executeMethod(method);data=method.getResponseBody();method.releaseConnection();}catch(HttpExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}Documentdoc=null;try{Stringxml=newString(data,"UTF-8");doc=Do
6、cumentHelper.parseText(xml);}catch(DocumentExceptione){e.printStackTrace();LOG.error("parsexmlerror.");}catch(UnsupportedEncodingExceptione){e.printStackTrace();}ElementrootElem=doc.getRootElement();if(("0").equals(rootElem.elementText("status"))){//没有此路信息,不做处理Stringdes
7、cription=rootElem.element("front").elementText("description");sb.append(description);}}catch(Exceptione){returnnull;}sb=jq(sb);returnsb.toString();}/***获取矩形范围内的实时路况*@paramx1左上角经度*@paramy1左上角纬度*@paramx2右下角经度*@paramy2右下角纬度*@return*/publicStringBufferrectangle(doublex1,dou
8、bley1,doublex2,doubley2){StringBuffersb=newStringBuffer();try{HttpClienthttpClient=newHttpClient();Stringurl="
此文档下载收益归作者所有