根据经度和纬度返回地理位置 LocationAPi
2011-06-07 10:54
375 查看
View Code
publicclass LocationAPI
{
privatestaticstring GeoCodeUrl = ConfigurationManager.AppSettings["GeoCodeUrl"];
privatestaticstring GoogleGearUrl = ConfigurationManager.AppSettings["GoogleGearUrl"];
privatestaticstring UseGoogleReverse = ConfigurationManager.AppSettings["UseGoogleReverse"];
///<summary>
/// Initializes a new instance of the <see cref="LocationAPI"/> class.
///</summary>
public LocationAPI()
{
}
publicstaticstring GetAddressFromLL(string Lat, string Lng)
{
string url ="http://ws.geonames.org/findNearestAddress?lat="+ Lat +"&lng="+ Lng;
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 =1;
response = request.GetResponse();
stream = response.GetResponseStream();
reader =new StreamReader(stream, System.Text.Encoding.UTF8);
XmlDocument xDoc =new XmlDocument();
xDoc.Load(stream);
XmlNode xStreet = xDoc.SelectSingleNode("geonames/address/street");
XmlNode xStreetNumber = xDoc.SelectSingleNode("geonames/address/streetNumber");
XmlNode xPlacename = xDoc.SelectSingleNode("geonames/address/placename");
XmlNode xCountryCode = xDoc.SelectSingleNode("geonames/address/countryCode");
string address = xStreet.InnerText +""+ xStreetNumber.InnerText +", "+ xPlacename.InnerText +", "+ xCountryCode.InnerText +"";
return address;
}
catch(Exception ex)
{
DAL.Log.Write(DateTime.Now.ToString() +"\0"+ ex.Message.ToString() +"\r\n");
return"UnKnown";
}
finally
{
if (reader !=null) reader.Close();
if (stream !=null) stream.Close();
if (response !=null) response.Close();
}
}
}
publicclass LocationAPI
{
privatestaticstring GeoCodeUrl = ConfigurationManager.AppSettings["GeoCodeUrl"];
privatestaticstring GoogleGearUrl = ConfigurationManager.AppSettings["GoogleGearUrl"];
privatestaticstring UseGoogleReverse = ConfigurationManager.AppSettings["UseGoogleReverse"];
///<summary>
/// Initializes a new instance of the <see cref="LocationAPI"/> class.
///</summary>
public LocationAPI()
{
}
publicstaticstring GetAddressFromLL(string Lat, string Lng)
{
string url ="http://ws.geonames.org/findNearestAddress?lat="+ Lat +"&lng="+ Lng;
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 =1;
response = request.GetResponse();
stream = response.GetResponseStream();
reader =new StreamReader(stream, System.Text.Encoding.UTF8);
XmlDocument xDoc =new XmlDocument();
xDoc.Load(stream);
XmlNode xStreet = xDoc.SelectSingleNode("geonames/address/street");
XmlNode xStreetNumber = xDoc.SelectSingleNode("geonames/address/streetNumber");
XmlNode xPlacename = xDoc.SelectSingleNode("geonames/address/placename");
XmlNode xCountryCode = xDoc.SelectSingleNode("geonames/address/countryCode");
string address = xStreet.InnerText +""+ xStreetNumber.InnerText +", "+ xPlacename.InnerText +", "+ xCountryCode.InnerText +"";
return address;
}
catch(Exception ex)
{
DAL.Log.Write(DateTime.Now.ToString() +"\0"+ ex.Message.ToString() +"\r\n");
return"UnKnown";
}
finally
{
if (reader !=null) reader.Close();
if (stream !=null) stream.Close();
if (response !=null) response.Close();
}
}
}
相关文章推荐
- 凨-百度地图API之地图标注(JS版),地理位置信息,根据地址获取经度纬度
- 开发你的LBS应用,使用Google地图引擎,根据地理位置获取纬度、经度。
- 根据用户坐标返回用户地理位置,并且统计用户
- Android 获取地理位置的经度和纬度
- Android 获取地理位置的经度和纬度(zz)
- Android编程获取地理位置的经度和纬度实例
- 百度地图根据地址返回经度纬度 php
- Android 自带 获取地理位置的经度和纬度
- Android 获取地理位置的经度和纬度
- Android 获取地理位置的经度和纬度
- Node.js和PHP根据ip获取地理位置的方法
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- CLGeocoder 根据地理位置获取经纬度,根据经纬度获取地理位置
- Google 根据用户地理位置和搜索历史定制搜索结果
- 根据地址获取经度和纬度
- JS根据IP得到经纬度、当前具体地理位置
- 根据IP地址获得地理位置
- java根据ip获取地理位置
- 百度地图 根据关键字搜索 并返回信息列表并根据选择位置信息得到经纬度
- 夺命雷公狗---微信开发07----接收地理位置消息,并用文本方式返回