Baidu Map get address information according to coordinates

Source: Internet
Author: User
Tags error code zip


Note: This method, if used for encoding, depends on the actual individual needs. Please refer to API parameter comments in detail.

Baidu Api:http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-geocoding

Baidu Open Platform: http://developer.baidu.com/map/jsdemo.htm#c1_2

private string GetAddress (String lng, string lat) {try {string url = @ "h ttp://api.map.baidu.com/geocoder/v2/?ak=e4805d16520de693a3fe707cdc962045&callback=renderreverse&
                location= "+ Lat +", "+ LNG + @" &output=xml&pois=1 ";
                WebRequest request = webrequest.create (URL); Request.
                Method = "POST";
                XmlDocument xmldoc = new XmlDocument ();
                string senddata = Xmldoc.innerxml;

                byte[] ByteArray = Encoding.Default.GetBytes (SendData); Stream DataStream = Request.
                GetRequestStream ();
                Datastream.write (ByteArray, 0, bytearray.length);

                Datastream.close (); WebResponse response = Request.
                GetResponse (); DataStream = Response.
                GetResponseStream ();
                StreamReader reader = new StreamReader (DataStream, System.Text.Encoding.GetEncoding ("Utf-8")); String responseXML = reader.

                ReadToEnd ();
                XmlDocument XML = new XmlDocument (); Xml.
                LOADXML (Responsexml); String status = XML. Documentelement.selectsinglenode ("status").
                InnerText; if (status = = "0") {xmlnodelist nodes = XML.
                    Documentelement.getelementsbytagname ("formatted_address"); if (nodes. Count > 0) {return nodes[0].
                    InnerText;
                } else return "did not get location information, error code 3";
                } else {return ' did not get location information, error code 1 ';
            }} catch (System.Exception ex) {return "did not get location information, error code 2"; }
        }

Parameters in the URL:

Parameters whether you must Default Value format Examples meaning
Coordtype Whether Bd09ll Bd09ll Baidu latitude and longitude coordinates The type of coordinates, currently supported by the type of coordinates include: Bd09ll (Baidu latitude and longitude coordinates), GCJ02LL (national survey of latitude and longitude coordinates), Wgs84ll (GPS latitude and longitude)
Location Is No 38.76623,116.43213 lat< latitude >,lng< Longitude > Get addresses based on latitude and longitude coordinates
POIs Whether 0 0 Shows if the poi,0 around the specified location is not displayed, 1 is displayed. A value of 1 o'clock displays the POI within 100 meters of the perimeter.

Results returned by the Run method:

Room 1101-08, No. 27th Zhongguancun Street, Haidian District, Beijing

Results returned from the Baidu API:

<?xml version= "1.0" encoding= "Utf-8"?>-<GeocoderSearchResponse> <status>0</status>-<re Sult>-<location> <lat>39.983424051248</lat> <lng>116.32298703399</lng> </loc ation> <formatted_address> 27th, Zhongguancun Avenue, Haidian District, Beijing, 1101-08, room </formatted_address> <business> Zhongguancun, Renmin University, Suzhou Street, China </business>-<addressComponent> <streetnumber/> <street> Zhongguancun Avenue </street> <distri ct> Haidian District </district> <city> Beijing </city> <province> Beijing </province> </addresscomponen 
  T> <cityCode>131</cityCode>-<pois>-<poi> <addr> Zhongguancun West Side south (Zhongguancun Science Park) </addr> <distance>0.050000</distance> <name> Zhongguancun Building </name> <poiType> office Building, business building </poitype > <tel> (010) 82856666</tel> <zip>100000</zip>-<point> <x>116.32298658484& Lt;/x> <y>39.983423843929</y> </point> </poi>-<poi> <addr> 27th Zhongguancun Avenue </addr> <distance>0.05000 0</distance> <name> Meizhou Dongpo Restaurant Zhongguancun shop </name> <poiType> Chinese restaurant, dining </poiType> <tel> (010) 8285 6948</tel> <zip/>-<point> <x>116.32298658484</x> <y>39.983423843929</y& 
  Gt </point> </poi>-<poi> <addr> Zhongguancun Avenue 27th </addr> &LT;DISTANCE&GT;0.050000&LT;/DISTANCE&G 
  T <name> China People's property insurance Zhongguancun sales </name> <poiType> China People's property insurance, insurance company, Finance </poiType> <tel> (010) 82856779 </tel> <zip>100000</zip>-<point> <x>116.32298658484</x> <y>39.9834238 43929</y> </point> </poi>-<poi> <addr> Beijing Haidian </addr> <distance>94.432 081</distance> <name> Photosynthesis Study </name> <poiType> book audio, shopping </poiType> <tel/> < Zip/>-&Lt;point> <x>116.32239334388</x> <y>39.983890240676</y> </point> </poi>- <poi> <addr> Zhongguancun Avenue, 27th </addr> <distance>42.195731</distance> <name> CCB Zhongguancun Branch </ 
  name> <poiType> China Construction Bank, banking, finance </poiType> <tel/> <zip>100000</zip>-<point> 
  <x>116.32292037972</x> <y>39.983711118168</y> </point> </poi>-<poi>  
  <addr> Beijing Haidian District </addr> <distance>62.342644</distance> <name> Haidian Hospital-laser plastic Surgery and beauty Department </name> <poiType> Beauty salon, Life services </poiType> <tel/> <zip/>-<point> <x>116.32317954086 </x> <y>39.98301950182</y> </point> </poi>-<poi> <addr> Zhongguancun Avenue, 19th, new China customs shopping Center 1 floor </addr> <distance>112.983688</distance> <name> Starbucks New closing </name> <poiType> Starbucks , cafe, casual dining, dining &LT;/POITYPE&GT <tel> (010) 82486056</tel> <zip/>-<point> <x>116.32218215226</x> <y>39 .983899777278</y> </point> </poi> </pois> </result> &LT;/GEOCODERSEARCHRESPONSE&G T

XML Description:

name type Description
Status constant Returns the result status value, returns 0 successfully, and other values see appendix.
Location Lat Latitude coordinates
Lng Longitude coordinates
Formatted_address Structured address information
Business Information in the business district, such as "Renmin University, Zhongguancun, Suzhou Street"
Addresscomponent City City Name
District County name
Province Province name
Street Street name
Street_number Street number
POIs (Peripheral poi Array) Addr Address information
Cp Data sources
Distance Distance from coordinate point
Name Poi Name
Poitype POI types, such as ' office building, business building '
Point POI coordinates {x, y}
Tel Phone
Uid POI Unique identification
Zip Zip

Appendix:

Return Code definition
0 Normal
1 Server Internal Error
2 Invalid request parameter
3 Permission validation failed
4 Quota check failed
5 AK does not exist or is illegal
101 Service disabled
102 Not through the whitelist or the security code is wrong.
2xx No permissions
3xx Quota Error

Reprint Address http://www.cnblogs.com/_zjl/archive/2013/11/19/3431525.html

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.