百度地图坐标快速转换方法 – 码农在线

百度地图坐标快速转换方法

开发用到了百度地图相关内容,以下是一个百度地图坐标转换方法,仅供参考
////// 百度地图坐标转换 限制100条/////////public ToBaiduJson TransBaidu(string location){location = location.Trim(';');string url = String.Format("http://api.map.baidu.com/geoconv/v1/?coords={0}&from=1&to=5&ak={1}", location, AppUtility.PubFun.BaiduAK);var result = new WebClient().DownloadString(url);JavaScriptSerializer js = new JavaScriptSerializer(); //实例化一个能够序列化数据的类ToBaiduJson baiduJson = js.Deserialize(result); //将json数据转化为对象类型并赋值给listreturn baiduJson;} ///百度地图json格式 public struct ToBaiduJson { public string status { get; set; } public string message { get; set; } public List<Result> result; } public struct Result { public string x { get; set; } public string y { get; set; }//数组处理 };

百度地图经纬度转换为具体地址:

////// 百度地址转换为具体地址//////public string TransAddress(string location){string addr = "";location = location.Trim(';');string url = String.Format("http://api.map.baidu.com/geocoder/v2/?ak={0}&location={1}&output=json&pois=0", AppUtility.PubFun.BaiduAK, location);var client = new WebClient();client.Encoding = System.Text.Encoding.UTF8;var result = client.DownloadString(url);JObject jresult = (JObject)JsonConvert.DeserializeObject(result);try{addr = jresult["result"]["formatted_address"].ToString();}catch{}return addr;}
具体详见百度地图Api