• 根据名称获取经纬度


     1  public static string[] GetValue(Sheet_Excel model)
     2         {
     3             MessageModel result = new MessageModel();
     4             string[] arrys = new string[] { };
     5             try
     6             {
     7                 string ak = "BfH08PCAsZ8SfbiXXEXRkSzn4MA00Mdk";
     8                 // string ak = "r8fiyxWjDHfFP0AUztl4avxqsocvlXuZ";11                 var _city = model.City;
    12                 var address = model.Address;
    13                 //address = address.Replace("#", "");
    14 
    15                 var urlName = $"{address}";18 
    19                 //pois 是否搜索周边 0或1
    20                 //string Url = @"http://api.map.baidu.com/geocoding/v3/?address=" + urlName + "&output=json&ak=" + ak + "";
    21                 string Url = $"http://api.map.baidu.com/geocoding/v3/?address={urlName}&output=json&ak={ak}";
    22                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
    23                 request.KeepAlive = false;
    24                 request.Method = "GET";
    25                 request.ContentType = "application/json";
    26                 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    27                 {
    28                     using (Stream myResponseStream = response.GetResponseStream())
    29                     {
    30                         // StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
    31                         using (StreamReader myStreamReader = new StreamReader(myResponseStream))
    32                         {
    33                             string responseString = myStreamReader.ReadToEnd();
    34                             var jo = JsonConvert.DeserializeObject<JObject>(responseString);
    35                             string lat = "", lng = "";
    36                             if (string.Equals(jo["status"].ToString(), "0") && jo["result"].ToString() != "[]")
    37                             {
    38                                 lat = jo["result"]["location"]["lat"].ToString();
    39                                 lng = jo["result"]["location"]["lng"].ToString();
    40                             }
    41 
    42                             arrys = new string[] { lng, lat };
    43                         }
    44                     }
    45                 }
    46                 result.response = arrys;
    47             }
    48             catch (Exception ex) { result.msg = ex.ToString(); }
    49 
    50             Thread.Sleep(200);
    51 
    52             return arrys;
    53         }
  • 相关阅读:
    ecshop后台根据条件查询后不填充table 返回的json数据,content为空?
    smarty中判断一个变量是否存在于一个数组中或是否存在于一个字符串中?
    getJSON回调函数不执行问题?
    高德地图关键字搜索删除上一次搜索的Marker
    多表连接查询详解
    网址图标设置
    CSS 引入方式 选择器
    Html 表单标签 Form
    Html 基本标签
    Python Socket实现简单web服务器
  • 原文地址:https://www.cnblogs.com/lyboke/p/14844674.html
Copyright © 2020-2023  润新知