zoukankan      html  css  js  c++  java
  • 根据经度和纬度返回地理位置 LocationAPi

    View Code
    publicclass LocationAPI
    {
    privatestaticstring GeoCodeUrl = ConfigurationManager.AppSettings["GeoCodeUrl"];
    privatestaticstring GoogleGearUrl = ConfigurationManager.AppSettings["GoogleGearUrl"];
    privatestaticstring UseGoogleReverse = ConfigurationManager.AppSettings["UseGoogleReverse"];

    ///<summary>
    /// Initializes a new instance of the <see cref="LocationAPI"/> class.
    ///</summary>
    public LocationAPI()
    {

    }

    publicstaticstring GetAddressFromLL(string Lat, string Lng)
    {

    string url ="http://ws.geonames.org/findNearestAddress?lat="+ Lat +"&lng="+ Lng;
    WebResponse response
    =null;
    Stream stream
    =null;
    StreamReader reader
    =null;

    try
    {
    HttpWebRequest request
    = (HttpWebRequest)WebRequest.Create(url);
    request.UserAgent
    =@"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.40607; .NET CLR 1.1.4322)";
    request.Timeout
    =1;
    response
    = request.GetResponse();
    stream
    = response.GetResponseStream();
    reader
    =new StreamReader(stream, System.Text.Encoding.UTF8);
    XmlDocument xDoc
    =new XmlDocument();
    xDoc.Load(stream);
    XmlNode xStreet
    = xDoc.SelectSingleNode("geonames/address/street");
    XmlNode xStreetNumber
    = xDoc.SelectSingleNode("geonames/address/streetNumber");
    XmlNode xPlacename
    = xDoc.SelectSingleNode("geonames/address/placename");
    XmlNode xCountryCode
    = xDoc.SelectSingleNode("geonames/address/countryCode");
    string address = xStreet.InnerText +""+ xStreetNumber.InnerText +", "+ xPlacename.InnerText +", "+ xCountryCode.InnerText +"";
    return address;

    }
    catch(Exception ex)
    {
    DAL.Log.Write(DateTime.Now.ToString()
    +"\0"+ ex.Message.ToString() +"\r\n");
    return"UnKnown";
    }
    finally
    {
    if (reader !=null) reader.Close();
    if (stream !=null) stream.Close();
    if (response !=null) response.Close();
    }
    }
    }
  • 相关阅读:
    解决 Cordova 打包 vue项目为 APP 后,在安卓平台下 touchMove 事件不生效的问题
    解决微信内置浏览器里,下拉无法捕获 touchEnd 事件
    记录 React-native 项目中的各种坑坑
    内存型游戏外挂讲解
    浅谈数据抓取的几种方法
    php链表笔记:合并两个有序链表
    php链表笔记:链表的检测
    php链表笔记:单链表反转
    使用UUID和int自增主键的区别
    lumen框架使用Elasticsearch详解
  • 原文地址:https://www.cnblogs.com/lelese7en/p/2074124.html
Copyright © 2011-2022 走看看