查找IP位置 \ c# 通过经纬度 查询地址、区域信息
2011-07-07 15:44
507 查看
查IP位置: http://www.youdao.com/smartresult-xml/search.s?type=ip&q=218.30.189.31
返回:
<smartresult>
<product type="ip">
<ip>218.30.189.31</ip>
<location>天津市 电信</location>
</product>
</smartresult>
//webclient客户端对象
WebClient client = new WebClient();
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//请求地址
client.Encoding = Encoding.UTF8;//编码格式
string responseTest = client.DownloadString(url);
//下载xml响应数据
string address = "";//返回的地址
XmlDocument doc = new XmlDocument();
//创建XML文档对象
if (!string.IsNullOrEmpty(responseTest))
{
doc.LoadXml(responseTest);//加载xml字符串
//查询状态信息
string xpath = @"GeocodeResponse/status";
XmlNode node = doc.SelectSingleNode(xpath);
string status = node.InnerText.ToString();
if (status == "OK") {
//查询详细地址信息
xpath = @"GeocodeResponse/result/formatted_address";
node = doc.SelectSingleNode(xpath);
address = node.InnerText.ToString();
//查询地区信息
XmlNodeList nodeListAll = doc.SelectNodes("GeocodeResponse/result");
XmlNode idt = nodeListAll[0];
XmlNodeList idts = idt.SelectNodes("address_component[type='sublocality']");
//address_component[type='sublocality']表示筛选type='sublocality'的所有相关子节点;
XmlNode idtst = idts[0];
string area = idtst.SelectSingleNode("short_name").InnerText;
address = address + "," + area;
}
}
address就是获取到的具体地址信息和区域信息;
返回:
<smartresult>
<product type="ip">
<ip>218.30.189.31</ip>
<location>天津市 电信</location>
</product>
</smartresult>
//webclient客户端对象
WebClient client = new WebClient();
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//请求地址
client.Encoding = Encoding.UTF8;//编码格式
string responseTest = client.DownloadString(url);
//下载xml响应数据
string address = "";//返回的地址
XmlDocument doc = new XmlDocument();
//创建XML文档对象
if (!string.IsNullOrEmpty(responseTest))
{
doc.LoadXml(responseTest);//加载xml字符串
//查询状态信息
string xpath = @"GeocodeResponse/status";
XmlNode node = doc.SelectSingleNode(xpath);
string status = node.InnerText.ToString();
if (status == "OK") {
//查询详细地址信息
xpath = @"GeocodeResponse/result/formatted_address";
node = doc.SelectSingleNode(xpath);
address = node.InnerText.ToString();
//查询地区信息
XmlNodeList nodeListAll = doc.SelectNodes("GeocodeResponse/result");
XmlNode idt = nodeListAll[0];
XmlNodeList idts = idt.SelectNodes("address_component[type='sublocality']");
//address_component[type='sublocality']表示筛选type='sublocality'的所有相关子节点;
XmlNode idtst = idts[0];
string area = idtst.SelectSingleNode("short_name").InnerText;
address = address + "," + area;
}
}
address就是获取到的具体地址信息和区域信息;
相关文章推荐
- c# 通过经纬度 查询地址、区域信息
- c# 通过经纬度查询 具体的地址和区域名称
- 借助百度api通过经纬度查询位置信息
- C#根据用户IP地址查询用户信息
- C# 调用IP库(QQWry.Dat)查询IP位置及自动升级IP库方法(附IP库下载地址及相关dll下载)
- java程序调用百度Geocoding API逆地址解析通过经纬度查询位置
- C# 调用IP库(QQWry.Dat)查询IP位置及自动升级IP库方法(附IP库下载地址及相关dll下载)
- 如何通过命令行查找一个IP的地理位置信息
- 百度地图的反地址解析(通过经纬度查询地址信息)
- .NET Core 开源工具 IPTools - 快速查询 IP 地理位置、经纬度信息
- C# 调用IP库(QQWry.Dat)查询IP位置及自动升级IP库方法(附IP库下载地址及相关dll下载)
- 百度地图通过经纬度获取地址信息
- [010] 百度地图API之根据经纬度查询地址信息(Android)
- python使用在线API查询IP对应的地理位置信息实例
- 通过GeoIP2分析访问者IP获取地理位置信息
- 位置信息类API调用的代码示例合集:中国省市区查询、经纬度地址转换、POI检索等
- 如何通过经纬度获取地址信息?
- Android Map Api 使用和开发(2) 定位我的位置、地图弹出泡泡、通过经纬度获取地址
- C#实现根据IP 查找真实地址
- 如何通过百度地图将经纬度转换为地址信息