0
点赞
收藏
分享

微信扫一扫

jquery 获取 IP地址与地理位置


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​​

获取地理位置 具体到市

$(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)

}
});
});

<script src="jquery.min.js"></script>

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

获取IP地址

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>

$("span").html(returnCitySN["cip"]);

<span></span>

jquery 获取 IP地址与地理位置_json

举报

相关推荐

0 条评论