JS獲取當前網絡定位

方法一:

<html>
<head>
<title>獲取地址</title>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script>
    var cityCode=returnCitySN.cid;
    document.write('<hr><br><h1> 老鐵位置:'+JSON.stringify(returnCitySN)+'</h1>');
</script>
</head>
<body>
</body>
</html>

效果:

 轉載地址:https://blog.csdn.net/HaHa_Sir/article/details/82627997

方法二:

百度地圖獲取

<html>
<head>
<title>獲取地址</title>

<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">

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

</head>
<body>
<script> 
$.getScript("https://api.map.baidu.com/location/ip?ak=自己的&callback=showLocation");
 function showLocation(data) {
 console.log(data.content.address_detail);
 alert(data.content.address_detail.city);
 alert(data.content.address_detail.province);
} 
</script>
</body>
</html>

 效果:

轉載地址:https://www.cnblogs.com/cwmizlp/p/9972972.html 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章