Recently, the project needs to query the specific address and region by latitude, through the query network resources, found that most of the provided to get the specific address of the region or the name of the city is not very good grasp; I got myself A:
Copy Code code as follows:
WebClient Client Objects
WebClient client = new WebClient ();
String url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + Latitude + "," + Longitude + "&language=zh-cn&am P;sensor=false ";//Request Address
Client. Encoding = encoding.utf8;//encoding format
String responsetest = client. downloadstring (URL);
Downloading XML response data
string address = "";//returned addresses
XmlDocument doc = new XmlDocument ();
Creating an XML Document Object
if (!string. IsNullOrEmpty (ResponseTest))
{
Doc. Loadxml (ResponseTest);//Load XML string
Query status information
string XPath = @ "Geocoderesponse/status";
XmlNode node = doc. selectSingleNode (XPath);
String status = node. Innertext.tostring ();
if (status = = "OK") {
Query Detail Address information
XPath = @ "Geocoderesponse/result/formatted_address";
node = doc. selectSingleNode (XPath);
Address = node. Innertext.tostring ();
Query Area Information
XmlNodeList Nodelistall = doc. SelectNodes ("Geocoderesponse/result");
XmlNode IDT = nodelistall[0];
XmlNodeList Idts = IDT. SelectNodes ("address_component[type= ' sublocality ')");
Address_component[type= ' sublocality '] means to filter all dependent subnodes of type= ' sublocality ';
XmlNode idtst = idts[0];
String area = Idtst. selectSingleNode ("Short_name"). InnerText;
Address = address + "," + area;
}
}
Address is to obtain the specific location information and regional information;