您好,登錄后才能下訂單哦!
這篇文章主要介紹在網(wǎng)站上添加谷歌定位信息的方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
我們可以很容易地使用HTML5導(dǎo)航對象獲取當(dāng)前位置。請按照以下步驟來獲得城市/國家的細節(jié)。
首先包括jQuery庫
JavaScript Code復(fù)制內(nèi)容到剪貼板
<script type="text/javascript" src="jquery.js"></script> jQuery(function() { //call navigator object to get latitude and logtitute if(navigator.geolocation) { //getting current latitude and longtitude navigator.geolocation.getCurrentPosition(function(position) { //get location details based on latitude and longtitude from Google var jsonUrl = "https://maps.googleapis.com/maps/api/geocode/json?latlng="+position.coords.latitude+","+position.coords.longitude jQuery.getJSON(jsonUrl , function( data ) { var results = data.results[0]; console.info(results); //check firebug alert(results.address_components[5].long_name); //City alert(results.address_components[6].long_name); //State alert(results.address_components[7].long_name); //Country }, function(){ alert('Failed to get Location Details...'); }); return false; }); }});
以上是在網(wǎng)站上添加谷歌定位信息的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。