发布:2021/4/9 11:24:45作者:管理员 来源:本站 浏览次数:1209
var address = "徐州丰沙路与师顺路交叉口";Console.WriteLine(str);
//百度api
private static string url = @"http://api.map.baidu.com/geocoder/v2/?location={0}&output=json&ak=WEc8RlPXzSifaq9RHxE1WW7lRKgbid6Y";
/// <summary>
/// 根据经纬度获取地理位置
/// </summary>
/// <param name="lat">纬度</param>
/// <param name="lng">经度</param>
/// <returns>具体的地埋位置</returns>
public static JObject GetLocation(string lat, string lng)
{
HttpClient client = new HttpClient();
string location = string.Format("{0},{1}", lat, lng);
string bdUrl = string.Format(url, location);
string result = client.GetStringAsync(bdUrl).Result;
var locationResult = (JObject)JsonConvert.DeserializeObject(result);
/*
if (locationResult == null || locationResult["result"] == null || locationResult["result"]["formatted_address"] == null)
return string.Empty;
var address = Convert.ToString(locationResult["result"]["formatted_address"]);
if (locationResult["result"]["sematic_description"] != null)
address += " " + Convert.ToString(locationResult["result"]["sematic_description"]);
*/
return locationResult;
}
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4