C#根据经纬度请求返回坐标实际地址
2011-04-23 16:28
323 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Globalization; using System.Net; using System.IO; using System.Configuration; using System.Xml; namespace WSGPSGateway.BLL { public class LocationAPI { public static string GetAddressByLatLng(string Lat, string Lng) { string CellUrl = "http://*******/CellAPI.aspx?Lat={0}&Lng={1}&Type=99"; string url = string.Format(CellUrl, Lat.ToString(), Lng.ToString()); string htm = GetPage(url); return htm; } public static string GetPage(string url) { if (url == "") return ""; WebResponse response = null; Stream stream = null; StreamReader reader = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.UserAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.40607; .NET CLR 1.1.4322)"; request.Timeout = 5000; response = request.GetResponse(); stream = response.GetResponseStream(); if (Get_Chartset(response.Headers["Content-Type"].ToString()).ToLower() == "gbk") { reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("GB2312")); } else if (Get_Chartset(response.Headers["Content-Type"].ToString()).ToLower() == "utf-8") { reader = new StreamReader(stream, System.Text.Encoding.UTF8); } else { reader = new StreamReader(stream, System.Text.Encoding.UTF8); } string buffer = reader.ReadToEnd(); return buffer; } catch (Exception ex) { DAL.Log.Write("google抓取数据失败异常! \0 错误记录:" + ex + "\r\n"); return ""; } finally { if (reader != null) reader.Close(); if (stream != null) stream.Close(); if (response != null) response.Close(); } } public static string Get_Chartset(string s) { if (s.ToLower() == "text/html") { return "gbk"; } else { int l = s.IndexOf("charset=") + 8; return s.Substring(l, s.Length - l); } } public string GetLatLng(string CID, string LAC) { string Url = "http://********/CellAPI.aspx?cid={0}&lac={1}"; Url = String.Format(Url, CID, LAC); string LatLng = ""; try { LatLng = BLL.LocationAPI.GetPage(Url); } catch (Exception ex) { DAL.Log.Write("获取基站地址发生错误! \0 错误记录:" + ex + "\r\n"); DAL.Log.Write("-----------------------------------------------------------\r\n"); } return LatLng; } } }
相关文章推荐
- C#根据经纬度请求返回坐标实际地址
- 根据地址返回地图经纬度-JAVA
- 百度地图API根据某个经纬度值(地理坐标)查询对应的地址信息以及该地址周边的POI(Point of Interest,兴趣点)信息
- JavaScript 根据两点的经纬度坐标,计算实际的直线距离
- java 根据地址返回经纬度
- R实例:根据经纬度坐标批量返回行政区域信息
- Google地图根据地址查询经纬度坐标
- 百度地图API,获取地址的经纬度,根据坐标位置获取地理位置,,获取两个地理坐标的直线距离
- 根据百度地图JSAPI查找某个地址的经纬度坐标
- Android 解决Map根据地址返回经纬度方法getFromLocationName()不能正常执行
- 根据地址返回经纬度(使用百度地图API)
- [转Iphone]根据经纬度坐标取详细地址(包括国,省,市,街道,号)
- 根据经纬度画多边形(返回各个顶点坐标)
- 根据地址返回坐标位置的百度地图api
- 根据经纬度坐标计算实际距离
- java/android 根据经纬度坐标计算两点的距离 (米/千米)
- 高德地图 Javascript web API 1.3根据输入的地址搜索位置的经纬度编码
- MKMapView地理编码(即根据地址来转换成坐标)
- 百度地图根据省市县定位,经纬度和地址信息互相转化JS示例