跨域相关文章: https://mp.csdn.net/postedit/85329628
(1)126api (速度较慢)
http://ip.ws.126.net/ipquery?ip=IP
https://ip.ws.126.net/ipquery?ip=IP (也支持https协议)
返回结果如下:
var lo="广东省", lc="广州市"; var localAddress={city:"广州市", province:"广东省"}
请求方式:
1
2
3
4
5
6
7
8
9var url = "https://ip.ws.126.net/ipquery?ip=IP"; // 查询当前用户ip所在地理位置 // var url = "https://ip.ws.126.net/ipquery?ip=36.32.224.255"; // 查询某一ip所在地理位置 $.getScript(url, function(){ var cityName = lc; // 城市名 }); });
(2)搜狐api
http://pv.sohu.com/cityjson?ie=utf-8 接口在4G网络或者其他情况返回的城市代码为CN,城市名为CHINA,不够精确,不建议使用
(3)太平洋:
http://whois.pconline.com.cn/
(4)百度:
http://lbsyun.baidu.com/index.php?title=webapi/ip-api
百度天气:
https://www.cnblogs.com/wangchengshen/p/3668946.html
https://blog.csdn.net/ixiaoyang/article/details/73556701
(5)淘宝
淘宝获取本机IP地址
接口地址:http://www.taobao.com/help/getip.php
传递参数:无
返回类型:jsonp
callback:ipCallback
返回值:
- ip:本机IP地址
请求示例:
- Request URL:http://www.taobao.com/help/getip.php
返回示例:
- ipCallback({ip:"115.159.152.210"})
备注:本接口只有返回IP地址的功能
淘宝获取IP详细信息
接口地址:http://ip.taobao.com/service/getIpInfo.php
传递参数:
- ip:要查询的IP地址
参数传递方式:GET/POST
返回类型:json
返回值:
- code:错误码(为零代表请求成功)
- country:国名
- country_id:国名(英文缩写)
- area:地域(如:华东)
- area_id:地域ID
- region:行政区
- region_id:行政区ID
- city:城市名
- city_id:城市ID
- isp:网络提供商
- isp_id:网络提供商ID
- ip:请求的IP地址
请求示例:
- Request URL:http://ip.taobao.com/service/getIpInfo.php?ip=115.159.152.210
返回示例:
- {
- "code":0,
- "data":{
- "country":"中国",
- "country_id":"CN",
- "area":"华东",
- "area_id":"300000",
- "region":"上海市",
- "region_id":"310000",
- "city":"上海市",
- "city_id":"310100",
- "county":"",
- "county_id":"-1",
- "isp":"腾讯网络",
- "isp_id":"1000153",
- "ip":"115.159.152.210"
- }
- }
备注:本接口来自淘宝IP地址库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120查询天气: 以下三方api地址均可使用http或https // 方式一: 太平洋API:查询当前用户位置信息 (推荐) $.ajax({ type: 'get', url: "https://whois.pconline.com.cn/ipJson.jsp", dataType: 'jsonp', data: { }, success: function (ret) { var cityName = ret.city; // 百度API:通过城市名查询天气 $.ajax({ type: 'get', url: 'https://api.map.baidu.com/telematics/v3/weather', dataType: 'jsonp', data: { location: cityName, output: 'json', ak: constant.WEATHER.AK }, success: function (res) { if (res.status === 'success') { var data = res.results[0]; var weather_data = data.weather_data[0]; var temperature = data.weather_data[0].date.split(':')[1].split(')')[0]; $('#position').text(data.currentCity); $('#temperature').text(temperature); $('#weather_now').text(weather_data.weather); $('#weather_temperature').text(weather_data.temperature.replace('~', '/')); } else { console.log('天气接口报错' + res.error); } }, error: function (error) { console.log(error); } }); } }); // 方式二:百度API:查询当前用户位置信息 (推荐) $.ajax({ type: 'get', url: "https://api.map.baidu.com/location/ip", dataType: 'jsonp', data: { ak: constant.WEATHER.AK }, success: function (ret) { var cityName = ret.content.address; // 百度API:通过城市名查询天气 $.ajax({ type: 'get', url: 'https://api.map.baidu.com/telematics/v3/weather', dataType: 'jsonp', data: { location: cityName, output: 'json', ak: constant.WEATHER.AK }, success: function (res) { if (res.status === 'success') { var data = res.results[0]; var weather_data = data.weather_data[0]; var temperature = data.weather_data[0].date.split(':')[1].split(')')[0]; $('#position').text(data.currentCity); $('#temperature').text(temperature); $('#weather_now').text(weather_data.weather); $('#weather_temperature').text(weather_data.temperature.replace('~', '/')); } else { console.log('天气接口报错' + res.error); } }, error: function (error) { console.log(error); } }); } }); // 方式三:126API:查询当前用户位置信息 (速度较慢) $.getScript("https://ip.ws.126.net/ipquery?ip=IP", function(){ var cityName = lc; // 百度API:通过城市名查询天气 $.ajax({ type: 'get', url: 'https://api.map.baidu.com/telematics/v3/weather', dataType: 'jsonp', data: { location: cityName, output: 'json', ak: constant.WEATHER.AK }, success: function (res) { if (res.status === 'success') { var data = res.results[0]; var weather_data = data.weather_data[0]; var temperature = data.weather_data[0].date.split(':')[1].split(')')[0]; $('#position').text(data.currentCity); $('#temperature').text(temperature); $('#weather_now').text(weather_data.weather); $('#weather_temperature').text(weather_data.temperature.replace('~', '/')); } else { console.log('天气接口报错' + res.error); } }, error: function (error) { console.log(error); } }); });
曾经有过的-百度高精度IP定位服务
https://www.jianshu.com/p/ae46bc471ac2
最后
以上就是简单巨人最近收集整理的关于第三方免费开放API-查询用户IP及所在地理位置,天气查询的全部内容,更多相关第三方免费开放API-查询用户IP及所在地理位置内容请搜索靠谱客的其他文章。
发表评论 取消回复