【发布时间】:2016-03-11 19:50:01
【问题描述】:
我正在尝试获取当前用户位置,但是当我重新加载代码时它会发生变化,即使我想每隔 x 秒获取一次位置。这是我的解决方案:
app.controller('geoCtrl', function($scope, $timeout, $cordovaBackgroundGeolocation, $ionicPlatform, $window, $cordovaGeolocation)
{
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude
var long = position.coords.longitude
alert('lat='+lat);
alert('long='+long);
}, function(err) {
// error
});
var watchOptions = {
timeout : 3000,
enableHighAccuracy: false // may cause errors if true
};
var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
null,
function(err) {
// error
},
function(position) {
var lat = position.coords.latitude
var long = position.coords.longitude
});
watch.clearWatch();
//-- End Geolocal
})
但这只有在我启动应用程序时才有效,请问有人知道吗?为了帮助我同步我的应用程序以每 x 秒获取一次位置数据 :)
【问题讨论】:
-
看起来您在创建手表后立即清除了它...
-
我想每 30 秒取一次结果!!!
标签: angularjs cordova service location ionic