我想将设备当前位置保存到一个变量中。有可能吗?
答案 0 :(得分:1)
您可以使用地理位置API获取当前位置。
http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/
使用上面提到的API将变量保存在变量中:
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);
}