In a relatively unfamiliar environment, we often find some infrastructure in the surrounding area, such as banks, shopping malls, and restaurants (and more eager to find toilets ). Using the map API provided by Baidu, you can simply implement it in your application. For more information, see the place API. We take the search for the surrounding bank as an example. We need to determine at least three parameters. The longitude and latitude of the location to be searched, the type or Keyword of the content to be searched.
Public String getpalace (string query, string Lat, string LNG) throws clientprotocolexception, ioexception {
Httpclient = new defaulthttpclient ();
String url = palcerequesturl (query, Lat, LNG );
Logger. Log (level. info, URL );
Httpget = new httpget (URL );
Responsehandler <string> responsehandler = new basicresponsehandler ();
String responsebody = httpclient.exe cute (httpget, responsehandler); // location XML
Logger. Log (level. info, "Baidu response:" + responsebody );
Return responsebody;
}
Public String palcerequesturl (string query, string Lat, string LNG) throws unsupportedencodingexception {
String url = wechatconstant. baseurl + "place/search? Query = "+ urlencoder. encode (query," UTF-8 ") +" & Key ="
+ Wechatconstant. mapkey + "& location =" + lat + "," + LNG + "& radius = 2000" + "& Output =" + wechatconstant. outputformat;
Return URL;
}
JUnit Test
@ Test
Public void testgetbaiduplace () throws exception {
Baidumapservice BMS = new baidumapservice ();
String response = BMS. getpalace ("bank", "39.915", "116.404 ");
List <baiduplaceresponse> List = baiduplaceresponse. getbaiduplace (response );
For (baiduplaceresponse Res: List ){
System. Out. println (res. tostring ());
}
}
Output content (omitted)
<? XML version = "1.0" encoding = "UTF-8"?>
<Placesearchresponse>
<Status> OK </status>
<Results>
<Result>
<Name> Industrial and Commercial Bank of China East Chang 'an street sub-branch </Name>
<Location>
<Lat> 39.915891 </LAT>
<LNG> 116.41867 </LNG>
</Location>
<Address> 1/F, West 3 office building, Oriental Plaza, no. 1, dongchang 'an Street, Dongcheng District </address>
<Uid> a025683c73033c35a21de987 </uid>
<Detail_url> http://api.map.baidu.com/place/detail? Uid = a025683c73033c35a21de987 & amp; Output = HTML & amp; Source = placeapi </detail_url>
<Tag> bank, Wangfujing/Dongdan </Tag>
</Result>
</Results>
</Placesearchresponse>
Baiduplaceresponse [name =
China Industrial and Commercial Bank of China East Chang 'an Street branch, telephone = NULL, address = Dongcheng District East Chang 'an Street 1 East Plaza West three office building 1
Floor, lat = 39.915891, lng = 116.41867, tag = NULL, detailurl = http://api.map.baidu.com/place/detail? Uid = a025683c73033c35a21de987 & amp; Output = HTML & amp; Source = placeapi]
Original article, reprinted Please note:Reprinted from http://www.qiyadeng.com/
Link:Query peripheral information