百度接口相关说明: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. 使用事件捕获实时捕获img是否加载完毕, 实现iframe内容高度自动适应

    如何判断在html中图片加载完毕呢? 给img图片加onload事件呗. 如何判断一个界面中所有的图片加载完毕呢? 给所有的图片加上onload事件呗. 如果有1000张图片那要怎么绑定事件呢? 我们 ...

  2. Oracle MERGE INTO 语句

    MERGE INTO USER_TEST T1 USING (SELECT '1001' AS ID,'王睿' AS NAME FROM dual) T2 ON ( T1.ID=T2.ID) WHEN ...

  3. solr-5.3部署到tomcat

    下载 solr 5.3 版本: http://www.apache.org/dyn/closer.lua/lucene/solr/5.3.0 下载 Tomcat(6以上版本),另外可以根据系统下载 3 ...

  4. Leetcode # 169, 229 Majority Element I and II

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  5. 【Codeforces-707D】Persistent Bookcase DFS + 线段树

    D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: ...

  6. 【bzoj1911】 Apio2010—特别行动队

    http://www.lydsy.com/JudgeOnline/problem.php?id=1911 (题目链接) 题意 给出一个序列,将序列分成连续的几段,每段的价值为a*s*s+b*s+c,其 ...

  7. android录音相关

    android的麦克风在现在的生活中发挥着很大的作用,打电话,视频聊天,语音识别等等. android sdk的api里提供了很方便的调用方法,下面写一个小的DEMO. 五个按钮:开始录音,停止,播放 ...

  8. Android成长日记-ViewPager的使用

    ViewPager在安卓应用中主要用于作为程序的引导页面,欢迎页面,以及其他的动画效果,下面将给你讲述ViewPager的使用 在Android3.0以上的Api中,提供了ViewPager的接口,所 ...

  9. ObjC 利用反射和KVC实现嵌套对象序列化成JSON数据

    原理: 0.创建一个新的可变字典:NSMutableDictionary 1.采用class_copyPropertyList函数遍历对象的属性 2.property_getName获取属性名,val ...

  10. MVC5-2 MVC的管道流与路由

    自定义Modue与Hander 之前讲了管道流中的Module与Hndler.现在我们可以去自定义Module和Handler Module 其实很简单,一共需要三个步骤 定义一个类去继承IHttpM ...