将当前设备位置保存在jQuery中的一个变量中
我想将设备当前位置保存到一个变量中。有可能吗?您可以使用地理位置API获取当前位置 使用上面提到的API将位置保存在变量中,如下所示:将当前设备位置保存在jQuery中的一个变量中,jquery,geolocation,device,Jquery,Geolocation,Device,我想将设备当前位置保存到一个变量中。有可能吗?您可以使用地理位置API获取当前位置 使用上面提到的API将位置保存在变量中,如下所示: var currentLocation; //this variable will store current location. jQuery(window).ready(function(){ jQuery("#btnInit").click(initiate_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);
}
发布您的代码…让我们看看您尝试了什么。