Javascript 使用W3C地理定位API';表位函数
我无法确定如何使用W3C地理定位API监视用户的位置。最简单的方法是什么?我只想更新用户的纬度和经度。我刚刚在一个项目中使用了它,我使用API和API本身来解决它Javascript 使用W3C地理定位API';表位函数,javascript,geolocation,Javascript,Geolocation,我无法确定如何使用W3C地理定位API监视用户的位置。最简单的方法是什么?我只想更新用户的纬度和经度。我刚刚在一个项目中使用了它,我使用API和API本身来解决它 navigator.geolocation.watchPosition(function(position){ // These variables update every time the location changes var Latitude = position.coords.latitude;
navigator.geolocation.watchPosition(function(position){
// These variables update every time the location changes
var Latitude = position.coords.latitude;
var Longitude = position.coords.longitude;
}, function(error){
// You can detect the reason and alert it; I chose not to.
alert('We could not get your location');
},{
// It'll stop looking after an hour. Enabling high accuracy tells it to use GPS if it's available
timeout: 5000,
maximumAge: 600000,
enableHighAccuracy: true
});
希望这有帮助 我刚刚在一个项目中使用了它,我使用了API和它本身
navigator.geolocation.watchPosition(function(position){
// These variables update every time the location changes
var Latitude = position.coords.latitude;
var Longitude = position.coords.longitude;
}, function(error){
// You can detect the reason and alert it; I chose not to.
alert('We could not get your location');
},{
// It'll stop looking after an hour. Enabling high accuracy tells it to use GPS if it's available
timeout: 5000,
maximumAge: 600000,
enableHighAccuracy: true
});
希望这有帮助 如果您已经有一些代码供我们查看,请提供。如果您已经有一些代码供我们查看,请提供。