前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jquery 获取 IP地址与地理位置

jquery 获取 IP地址与地理位置

原创
作者头像
有勇气的牛排
发布2023-06-25 23:17:04
4010
发布2023-06-25 23:17:04
举报
文章被收录于专栏:有勇气的牛排专栏

1. 接口

搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson

搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8

获取城市位置:http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6

2 获取地理位置 具体到市

代码语言:javascript
复制
$(function () {
	$.ajax({
		url: 'http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6',
		type: 'POST',
		dataType: 'jsonp',
		success: function (res) {
			console.log(res)
            console.log(res.address)
            console.log(res.content.address)
            console.log(res.content.address_detail.adcode)
            console.log(res.content.address_detail.city)
            console.log(res.content.address_detail.city_code)
            console.log(res.content.address_detail.district)
            console.log(res.content.address_detail.province)
            console.log(res.content.address_detail.street)
            console.log(res.content.address_detail.street_number)
	           
			}
		});
});
代码语言:html
复制
    <script src="jquery.min.js"></script>

    <div>
        <input id="province" type="text">
    </div>
    <button id="submit">提交</button>
    <script src="position.js"></script>

3 获取IP地址

代码语言:javascript
复制
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
代码语言:javascript
复制
$("span").html(returnCitySN["cip"]);
代码语言:html
复制
<span></span>
image.png
image.png

原文地址:

https://www.couragesteak.com/article/408

更多前端文章:

https://www.couragesteak.com/article/188

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 接口
  • 2 获取地理位置 具体到市
  • 3 获取IP地址
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档