js 定位当前城市之接口定位(搜狐、新浪、百度、腾讯API)
1.搜狐API<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script><script type="text/
·
1.搜狐API
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
console.log(returnCitySN)
//返回对象Object {cip: "122.70.200.146", cid: "110000", cname: "北京市"}
</script>
2.新浪API
<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
<script>
var msg = remote_ip_info;
console.log(msg)
//返回对象Object {ret: 1, start: -1, end: -1, country: "中国", province: "北京",city: "北京"…}
</script>
3.新浪apijsonp
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(_result) {
if (remote_ip_info.ret == '1') {
console.log('国家:' + remote_ip_info.country +'\n省:' + remote_ip_info.province + '\n市:' + remote_ip_info.city + '\n区:' + remote_ip_info.district + '\nISP:' + remote_ip_info.isp + '\n类型:' + remote_ip_info.type + '\n其他:' + remote_ip_info.desc);
//返回结果 国家:中国 省:北京 市:北京 区: ISP: 类型: 其他:
} else {
alert('没有找到匹配的IP地址信息!');
}
});
4.百度地图api
function showLocation(data) {
console.log(data.content.address_detail.city);
}
$.getScript("http://api.map.baidu.com/location/ip?ak=百度地图密匙&callback=showLocation");
5.腾讯地图api
$.getScript('https://apis.map.qq.com/ws/location/v1/ip?callback=showLocation&key=腾讯地图密匙&output=jsonp');
function showLocation(data) {
console.log(data.result.ad_info.city)
}
更多推荐
已为社区贡献1条内容
所有评论(0)