根据地址获取经度和纬度

来源:互联网 发布:网络视频编辑 编辑:程序博客网 时间:2024/04/28 19:15
        /// <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