title: JS - Promise + geolocation.watchPosition
body: <p>I'm trying to use JavaScript Promise with geolocation, but can't get to make it work correctly with <em>geolocation.watchPosition</em>, the <em>then</em> clause being called only once :</p>
  
  <pre><code>function Geolocation() {
    this._options = {
      enableHighAccuracy: true, 
      maximumAge        : 10000, 
      timeout           : 7000
    }
  }
  
  Geolocation.prototype = {
    get watchID() { return this._watchID; },
    set watchID(watchID) { this._watchID = watchID; },
    get options() { return this._options; },
    // hasCapability: function() { return "geolocation" in navigator; },
    _promise: function(promise) {
      var geolocation = this;
      if (promise == "getPosition")
        return new Promise(function(ok, err) {
          navigator.geolocation.getCurrentPosition(
            ok.bind(geolocation), err.bind(geolocation),
            geolocation.options
          );
        });
      else if (promise == "watchPosition")
        return new Promise(function(ok, err) {
          geolocation.watchID = navigator.geolocation.watchPosition(
            ok.bind(geolocation), err.bind(geolocation),
            geolocation.options
          );
        });
    },
    getPosition: function() { return this._promise('getPosition'); },
    watchPosition: function() {
      this.clearWatch();
      return this._promise('watchPosition');
    },
    clearWatch: function() {
      if (!this.watchID) return;
      navigator.geolocation.clearWatch(this.watchID);
      this.watchID = null;
    }
  };
  
  var geolocation = new Geolocation();
  geolocation.watchPosition()
    .then(
      function(position) {
        console.log("latitude: " + position.coords.latitude + " - longitude: " + position.coords.longitude)
      },
      function(error) {
        console.log("error: " + error);
      }
    )
  </code></pre>
  
  <p>I tried with an intermediary promise returned from <em>watchPosition/0</em>, but it returns the same result.</p>
  
  <p>What am I missing ?</p>