Query peripheral information

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.