我正在研究离子框架中的应用程序,我希望获得设备的位置 . 它适用于 getCurrentPosition 但是当我尝试使用 watchPosition 时,每当设备位置发生变化时我都可以获得新的位置 . 它什么都不做 . 我'm not sure what I '我错过了我的controllers.js代码

.controller('LocCtrl', function($scope,$cordovaGeolocation) {
  var posOptions = {timeout: 10000, enableHighAccuracy: false};
  $cordovaGeolocation
    .getCurrentPosition(posOptions)
    .then(function (position) {
      alert('Latitude: '        + position.coords.latitude        + '\n' +
          'Longitude: '         + position.coords.longitude         + '\n' +
          'Altitude: '          + position.coords.altitude          + '\n' +
          'Accuracy: '          + position.coords.accuracy          + '\n' +
          'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
          'Heading: '           + position.coords.heading           + '\n' +
          'Speed: '             + position.coords.speed             + '\n' +
          'Timestamp: '         + position.timestamp                + '\n');
    }, function(err) {
      alert(err);
    });

  var watchOptions = {
    timeout : 3000,
    enableHighAccuracy: false // may cause errors if true
  };
  var watch = $cordovaGeolocation.watchPosition(watchOptions);
  watch.promise.then(
    null,
    function(err) {
      alert("error:"+err);
    },
    function(position) {
      var lat  = position.coords.latitude
      var long = position.coords.longitude
      alert("Lat in Watch:"+lat);
  });
  $cordovaGeolocation.clearWatch(watch.watchId);
})

我使用了一些警报消息来查看发生了什么,在当前的设置中,它给出了两条警报消息给出 getCurrentPosition ,但是在更改设备位置时会发生注意 .