首页 > 其他 > 详细

批量地理位置解析

时间:2017-11-10 18:02:20      阅读:169      评论:0      收藏:0      [点我收藏+]

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;
}
}

批量地理位置解析

原文:http://www.cnblogs.com/daizhipeng/p/7815556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!