zoukankan      html  css  js  c++  java
  • C# 百度经纬度获取地址信息

    #region 经纬度获取地址
    public class BaiDuGeoCoding
    {
    public int Status { get; set; }
    public Result Result { get; set; }
    }

    public class Result
    {
    public Location Location { get; set; }

    public string Formatted_Address { get; set; }

    public string Business { get; set; }

    public AddressComponent AddressComponent { get; set; }

    public string CityCode { get; set; }
    }

    public class AddressComponent
    {
    /// <summary>
    /// 省份
    /// </summary>
    public string Province { get; set; }
    /// <summary>
    /// 城市名
    /// </summary>
    public string City { get; set; }

    /// <summary>
    /// 区县名
    /// </summary>
    public string District { get; set; }

    /// <summary>
    /// 街道名
    /// </summary>
    public string Street { get; set; }

    public string Street_number { get; set; }

    }

    public class Location
    {
    public string Lng { get; set; }
    public string Lat { get; set; }
    }

    public class HttpClientHelper
    {
    /// <summary>
    /// GET请求
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="url"></param>
    /// <returns></returns>
    public static T GetResponse<T>(string url) where T : class, new()
    {
    string returnValue = string.Empty;
    HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
    webReq.Method = "GET";
    webReq.ContentType = "application/json";
    using (HttpWebResponse response = (HttpWebResponse)webReq.GetResponse())
    {
    using (StreamReader streamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
    {
    returnValue = streamReader.ReadToEnd();
    T result = default(T);
    result = JsonConvert.DeserializeObject<T>(returnValue);
    return result;
    }
    }
    }
    }

    //百度地图Api Ak
    public const string BaiduAk = "9TxmFS8X1EXcUGZkqsDM4GKuayamwkbr";

    /// <summary>
    /// 经纬度 逆地理编码 Url 需要Format 0.ak 1.经度 2.纬度
    /// </summary>
    private const string BaiduGeoCoding_ApiUrl = "http://api.map.baidu.com/geocoder/v2/?ak={0}&location={1},{2}&output=json&pois=0";

    /// <summary>
    /// /// <summary>
    /// 经纬度 逆地理编码 Url 需要Format 0.经度 1.纬度
    /// </summary>
    /// </summary>
    public static string Baidu_GeoCoding_ApiUrl
    {
    get
    {
    return string.Format(BaiduGeoCoding_ApiUrl, BaiduAk, "{0}", "{1}");
    }
    }

    /// <summary>
    /// 根据经纬度 获取 地址信息
    /// </summary>
    /// <param name="lat">经度</param>
    /// <param name="lng">纬度</param>
    /// <returns></returns>
    public static BaiDuGeoCoding GeoCoder(string lat, string lng)
    {
    string url = string.Format(Baidu_GeoCoding_ApiUrl, lat, lng);
    var model = HttpClientHelper.GetResponse<BaiDuGeoCoding>(url);
    return model;
    }
    #endregion

  • 相关阅读:
    遥控按键上报键值映射问题
    AutoLock类
    Mutex互斥锁
    c++ 字符串和数字转换时的特殊处理
    pytorch实现MLP并在MNIST数据集上验证
    python实现直方图均衡化,理想高通滤波与高斯低通滤波
    python实现贝叶斯网络的概率推导(Probabilistic Inference)
    python+opencv实现车牌定位
    python添加高斯噪声和椒盐噪声,实现中值滤波和均值滤波,实现Roberts算子和Sobel算子
    c++学习笔记_6
  • 原文地址:https://www.cnblogs.com/lovecwq/p/13182757.html
Copyright © 2011-2022 走看看