搜狐方法有時會出問題,轉戰太平洋獲取的方法了,詳情進去下面鏈接查看,也比較簡單,而且獲取的數據比較全面
http://whois.pconline.com.cn/
引入搜狐獲取位置的 js,PC 端不太准確,移動端安卓,iOS, 試了都正常
1 <script typet="text/javascript" async="async" src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
引入后會得到省市名,如下
1 var returnCitySN = {"cip": "124.89.86.45", "cid": "610100", "cname": "陝西省西安市"};
需求復雜的話就建議用高德和百度的api 了。
以上