-1
我想將設備當前位置保存到一個變量中。可能嗎?將當前設備位置保存在jQuery中的一個變量中
我想將設備當前位置保存到一個變量中。可能嗎?將當前設備位置保存在jQuery中的一個變量中
您可以使用地理定位API來獲取當前位置。使用我上面所提到的API
http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/
保存在變量中的位置:
var currentLocation; //this variable will store current location.
jQuery(window).ready(function(){
jQuery("#btnInit").click(initiate_geolocation);
});
function initiate_geolocation() {
//store current location
currentLocation = navigator.geolocation.getCurrentPosition(handle_geolocation_query);
}
function handle_geolocation_query(position){
alert('Lat: ' + position.coords.latitude + ' ' +
'Lon: ' + position.coords.longitude);
}
發佈您的代碼...讓我們來看看你已經嘗試了什麼。 – pmandell 2013-04-25 13:28:16