百度接口相关说明:http://developer.baidu.com/map/ip-location-api.htm

返回是json格式,首先构建相关反系列化类:

 #region AddressForQueryIPFromBaidu
[Serializable]
public class AddressForQueryIPFromBaidu
{
public string Address { get; set; }
public Content Content { get; set; }
public string Status { get; set; }
}
[Serializable]
public class Content
{
public string Address { get; set; }
public Address_Detail Address_Detail { get; set; }
public Point Point { get; set; }
}
[Serializable]
public class Address_Detail
{
public string City { get; set; }
public string City_Code { get; set; }
public string District { get; set; }
public string Province { get; set; }
public string Street { get; set; }
public string Street_Number { get; set; }
}
[Serializable]
public class Point
{
public string X { get; set; }
public string Y { get; set; }
}
#endregion

接口调用方法:

 public static AddressForQueryIPFromBaidu GetAddressFromIP(string ipAddress)
{
string baiduKey = "59722ea6a425fbd81******80ee3ecbb";
string url = "http://api.map.baidu.com/location/ip?ak="+baiduKey+"&ip="+ipAddress+"&coor=bd09ll";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
string responseText = sr.ReadToEnd();
sr.Close();
sr.Dispose();
responseStream.Close();
string jsonData = responseText;
JavaScriptSerializer jss = new JavaScriptSerializer();
AddressForQueryIPFromBaidu addressForQueryIPFromBaidu = jss.Deserialize<AddressForQueryIPFromBaidu>(jsonData);
return addressForQueryIPFromBaidu;
}

C#使用百度API通过IP获取地理位置和坐标的更多相关文章

  1. 百度api:根据经纬度获取地理位置信息

    调用百度api,根据经度和纬度获取地理位置信息,返回Json. C#代码: using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Syste ...

  2. PHP通过IP 获取 地理位置(实例)

    发布:JB02   来源:脚本学堂  分享一例php代码,实现通过IP地址获取访问者的地理位置,在php编程中经常用到,有需要的朋友参考下吧.本节内容:PHP通过IP获取地理位置 例子: 复制代码代码 ...

  3. PHP通过IP 获取 地理位置(实例代码)

    发布:JB02   来源:脚本学堂 分享一例php代码,实现通过IP地址获取访问者的地理位置,在php编程中经常用到,有需要的朋友参考下吧.本节内容:PHP通过IP获取地理位置 例子: 复制代码代码示 ...

  4. PHP根据ip获取地理位置(通过高德地图接口)

    PHP根据ip获取地理位置(通过高德地图接口)<pre>//restapi.amap.com/v3/ip?key=2004f145cf3a39a72e9ca70ca4b2a1dc& ...

  5. 根据本地ip获取地理位置,再根据地理位置,获取天气

    import json,requestsfrom urllib.request import urlopenfrom pyquery import PyQuery as pqfrom lxml imp ...

  6. 百度地图用ip获取当前位置的经纬度(高精度)

    步骤比较简单先上百度地图API官网,申请一个应用AK(访问凭据):查看一下高进度定位的API,看看是否都符合要求下面直接上代码 /** * 根据ip获取地理坐标 * @param ip * @retu ...

  7. 百度接口通过ip获取用户所在地

    /** * 百度接口      * 通过用户ip获取用户所在地      * @param userIp      * @return      */ public static String get ...

  8. PHP 根据IP获取地理位置

    /** * 根据用户IP获取用户地理位置 * $ip 用户ip */ function get_position($ip){ if(empty($ip)){ return '缺少用户ip'; } $u ...

  9. (分享)根据IP获取地理位置(百度API)

    说明: 本程序调用的百度地图接口 http://lbsyun.baidu.com/index.php?title=webapi/high-acc-ip#h. 使用C#语言+VS2015 IDE开发 效 ...

随机推荐

  1. 【POJ 1113】Wall

    http://poj.org/problem?id=1113 夏令营讲课时的求凸包例题,据说是PKUSC2015的一道题 我WA两次错在四舍五入上了(=゚ω゚)ノ #include<cmath& ...

  2. 素数筛 poj 3518

    给你一个n 求包括n的一个非素数区间有多长 +1输出 #include<stdio.h> #include<string.h> #include<algorithm> ...

  3. 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    1.ListBox 的示例Controls/SelectionControl/ListBoxDemo.xaml <Page x:Class="Windows10.Controls.Se ...

  4. 22 java当中的数组

    class Test { public static void main(String args[]) { //数组的静态声明法 int arr[]={5,2,7,9,0}; //数组的动态声明法 i ...

  5. Python中remove,del和pop的区别

    以a=[1,2,3] 为例,似乎使用del, remove, pop一个元素2 之后 a都是为 [1,3], 如下:http://Novell.Me >>> a=[1,2,3] &g ...

  6. OneThink学习笔记01

    OneThink1.0开发手册: http://document.onethink.cn/manual_1_0.html 简介  OneThink是一个开源的内容管理框架,基于最新的ThinkPHP3 ...

  7. Eclipse配置PyDev插件来实现python开发环境

    1.安装python解释器(完成的略过) 2.安装PyDev: 首先需要去Eclipse官网下载:http://www.eclipse.org/,Eclipse需要JDK支持,如果Eclipse无法正 ...

  8. Maven报错: Missing artifact jdk.tools:jdk.tools:jar:1.7

    pom.xml 有小红叉,报错: Missing artifact jdk.tools:jdk.tools:jar:1.7 解决方法:(缺少一个jar包) http://blog.csdn.net/u ...

  9. js-JavaScript高级程序设计学习笔记17

    第21章  AJAX AJAX技术的核心是XMLHttpRequest对象.可以使用XHR对象取得新数据,然后通过DOM将新数据插入到页面中.无需刷新页面即可从服务器获得数据. 1.XHR对象. 如果 ...

  10. Jenkins配置MSBuild时使用环境变量

    [MSBuild Plugin]插件在使用环境变量有个很奇葩的方式,比如我们通常在Windows的节点机器上,使用WORKSPACE环境变量时,批处理应该这样写%WORKSPACE%,而有时插件确不能 ...