-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