批量地理位置解析
public class GisHelper
{
/// <summary>
/// 批量地理位置解析
/// </summary>
/// <param name="lonlat"></param>
/// <returns>index-->loc</returns>
public static Dictionary<string, string> GetLocation(List<Dictionary<string, string>> lonlat)
{
string posTemplate = "1,{0},{1},{2}";
Dictionary<string, string> lis = new Dictionary<string, string>();
try
{
WebClientEx client = new WebClientEx();
client.Encoding = Encoding.UTF8;
List<string> param = new List<string>();
int index = 0;
lonlat.ForEach(p =>
{
foreach (KeyValuePair<string, string> item in p)
{
string[] temp = item.Value.Split(',');
param.Add(string.Format(posTemplate, item.Key, temp[0], temp[1]));
index++;
}
});
string url = "http://{0}:{1}/stargis/Openlayers/GetCountrySeatHandler.aspx?requestInfos=";//xxx.xxx.xxx.xxx:10087 //xxx.xxx.xxx.xxx
string locationinfo = client.OpenRead(string.Format(url, "xxx.xxx.xxx.xxx", 10087) + string.Join(";", param.ToArray()));
if (locationinfo.Trim().Length > 0)
{
string[] temp = locationinfo.Trim().TrimStart('(').TrimEnd(')').Split(';');
foreach (var s in temp)
{
string[] ss = s.Split(',');
if (ss != null && ss.Length >= 3)
{
string sim = ss[1];
string loc = ss[2];
lis[sim] = loc;
}
}
}
}
catch (Exception ex)
{
LogHelper.Error("位置解析失败", ex);
}
return lis;
}
public static string GetLocation(string lon, string lat)
{
string location = string.Empty;
List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
Dictionary<string, string> dic = new Dictionary<string, string>();
dic["0"] = string.Format("{0},{1}", lon, lat);
list.Add(dic);
Dictionary<string, string> o = GetLocation(list);
if (o.ContainsKey("0"))
return o["0"];
return location;
}
}