這篇文章主要為大家展示了“web開發中怎么在網站上添加谷歌定位信息”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“web開發中怎么在網站上添加谷歌定位信息”這篇文章吧。
首先包括jQuery庫
<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;
});
}});以上是“web開發中怎么在網站上添加谷歌定位信息”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。