Commit 85bccea0 authored by 黄奎's avatar 黄奎

11

parent 8d546a10
...@@ -224,20 +224,20 @@ namespace Mall.Common.Plugin ...@@ -224,20 +224,20 @@ namespace Mall.Common.Plugin
/// <returns></returns> /// <returns></returns>
public static string[] GetGeocoderLatitude(string address) public static string[] GetGeocoderLatitude(string address)
{ {
string apiKey = "7d9fbeb43e975cd1e9477a7e5d5e192a";
var returnStr = new string[2] { "", "" }; var returnStr = new string[2] { "", "" };
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
string url = "http://api.map.baidu.com/geocoder?address=" + address + "&output=json&key=" + apiKey;
try try
{ {
string apiResult = client.GetStringAsync(url).Result; //string apiKey = "7d9fbeb43e975cd1e9477a7e5d5e192a";
var apiJson = JObject.Parse(apiResult); //string url = "http://api.map.baidu.com/geocoder?address=" + address + "&output=json&key=" + apiKey;
var resultJson = JObject.Parse(apiJson["result"].ToString()); //string apiResult = client.GetStringAsync(url).Result;
var locationJson = JObject.Parse(resultJson["location"].ToString()); //var apiJson = JObject.Parse(apiResult);
var lng = locationJson["lng"].ToString();//经度 //var resultJson = JObject.Parse(apiJson["result"].ToString());
var lat = locationJson["lat"].ToString();//纬度 //var locationJson = JObject.Parse(resultJson["location"].ToString());
returnStr[0] = lng; //var lng = locationJson["lng"].ToString();//经度
returnStr[1] = lat; //var lat = locationJson["lat"].ToString();//纬度
//returnStr[0] = lng;
//returnStr[1] = lat;
} }
catch catch
{ {
...@@ -246,31 +246,7 @@ namespace Mall.Common.Plugin ...@@ -246,31 +246,7 @@ namespace Mall.Common.Plugin
return returnStr; return returnStr;
} }
/// <summary>
/// 根据经纬度获取详细地址location
/// </summary>
/// <param name="latlng"></param>
/// <returns></returns>
public static string GetGeocoderAddress(string latlng)
{
string apiKey = "7d9fbeb43e975cd1e9477a7e5d5e192a";
HttpClient client = new HttpClient();
string url = "http://api.map.baidu.com/geocoder?location=" + latlng + "&output=json&key=" + apiKey;
try
{
string apiResult = client.GetStringAsync(url).Result;
var apiJson = JObject.Parse(apiResult);
var resultJson = JObject.Parse(apiJson["result"].ToString());
var locationJson = JObject.Parse(resultJson["addressComponent"].ToString());
var province = locationJson["province"].ToString();//省份
return province;
}
catch
{
}
return "";
}
/// <summary> /// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment