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 }