W3C home > Mailing lists > Public > public-device-apis@w3.org > June 2015

Re: [sensors] Dependency on [DOM] due to inheriting from EventTarget

From: gmandyam via GitHub <sysbot+gh@w3.org>
Date: Thu, 11 Jun 2015 15:42:50 +0000
To: public-device-apis@w3.org
Message-ID: <issue_comment.created-111177707-1434037369-sysbot+gh@w3.org>
Take the one-time location request example from the existing spec 
(where a fresh location is required) and show how the Sensor API 
applies.  (Yes - I know this is not a Promise-based API, but it can be
 adapted to be Promise-based).  Note that there are no DOM 
dependenices in the example as far as I can tell.

<code>
 // Request a position. We only accept cached positions whose age is 
not
    // greater than 10 minutes. If the user agent does not have a 
fresh
    // enough cached position object, it will immediately invoke the 
error
    // callback.
    navigator.geolocation.getCurrentPosition(successCallback,
                                             errorCallback,
                                             {maximumAge:600000, 
timeout:0});

    function successCallback(position) {
      // By using the 'maximumAge' option above, the position
      // object is guaranteed to be at most 10 minutes old.
      // By using a 'timeout' of 0 milliseconds, if there is
      // no suitable cached position available, the user agent 
      // will asynchronously invoke the error callback with code
      // TIMEOUT and will not initiate a new position
      // acquisition process.
    }

    function errorCallback(error) {
      switch(error.code) {
        case error.TIMEOUT:
          // Quick fallback when no suitable cached position exists.
          doFallback();
          // Acquire a new position object.
          navigator.geolocation.getCurrentPosition(successCallback, 
errorCallback);
          break;
        case ... // treat the other error cases.
      };
    }

    function doFallback() {
      // No fresh enough cached position available.
      // Fallback to a default position.
    }
</code>

-- 
GitHub Notif of comment by gmandyam
See https://github.com/w3c/sensors/issues/21#issuecomment-111177707
Received on Thursday, 11 June 2015 15:42:56 UTC

This archive was generated by hypermail 2.3.1 : Monday, 23 October 2017 14:54:05 UTC