您的位置:首页 > 其它

根据地址获取经度和纬度

2011-10-10 13:59 260 查看
/// <summary>
/// 根据地址获取经度和纬度
/// </summary>
public string GetlatlngByAddress(string address)
{
string result = string.Empty;
try
{
address = HttpUtility.UrlEncode(address, Encoding.UTF8);
result = GetWebContent("http://maps.google.com/maps/geo?q=" + address
+ "&output=xml&sensor=true&key=dc27b1d958ee7725aa1b6899af7b50816258da9bf3ffa0f736db1bf3ca24877b7a25104e7f587e1c");
XmlDocument xml = new XmlDocument();
xml.LoadXml(result);
XmlNamespaceManager xmlns = new XmlNamespaceManager(xml.NameTable);
xmlns.AddNamespace("e", "http://earth.google.com/kml/2.0");
result = xml.SelectSingleNode("e:kml/e:Response/e:Placemark/e:Point/e:coordinates", xmlns).InnerText;
}
catch
{
result = null;
}
return result;
}


PS:需要引用System.Web.dll
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: