using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Net; namespace Utility
{
public class GoogleMapHelper
{
public string GetAddress(string lat, string lng)
{
WebClient client = new WebClient();
string url = string.Format("http://maps.google.com/maps/api/geocode/xml?latlng={0},{1}&language=zh-CN&sensor=false", lat, lng);
client.Encoding = Encoding.UTF8;
try
{
string responseTest = client.DownloadString(url);
XmlDocument doc = new XmlDocument(); if (!string.IsNullOrEmpty(responseTest))
{
doc.LoadXml(responseTest); string xpath = @"GeocodeResponse/status";
XmlNode node = doc.SelectSingleNode(xpath);
string status = node.InnerText.ToString(); if (status == "OK")
{
xpath = @"GeocodeResponse/result/formatted_address";
node = doc.SelectSingleNode(xpath);
string address = node.InnerText.ToString();
return address;
}
}
}
catch
{
}
return "";
}
}
}