<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> <script type="text/javascript"> document.write('<b>'+'您的IP:'+returnCitySN["cip"]+' 您的位置:'+returnCitySN["cname"]+'</b>') </script>
方法一:搜狐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>
方法二:新浪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>
方法三:新浪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地址信息!'); } });
方法四: 百度地图api
function showLocation(data) { console.log(data.content.address_detail.city); } $.getScript("http://api.map.baidu.com/location/ip?ak=百度地图密匙&callback=showLocation");
方法五: 腾讯地图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) }