Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on my new understanding of what you are after, you want something like this. (Tested: in Opera - works, Firefox 3.6 &amp; Chrome 8 - not so much (I need more time to debug))</p> <p><strong>Scenario:</strong> Page attempts to get location... but user ignores the prompt completely thus there is no (accept or deny) and since the request for the location is never sent, there is no timeout either!</p> <p>Based on this you may want to add your own logic to handle this scenario. For the sake of this example, I'm going to prototype my own "wrapper" method. (for the picky - I'm not condoning using globals etc. I was just trying to get something to work)</p> <pre><code>navigator.geolocation.requestCurrentPosition = function(successCB, errorCB, timeoutCB, timeoutThreshold, options){ var successHandler = successCB; var errorHandler = errorCB; window.geolocationTimeoutHandler = function(){ timeoutCB(); } if(typeof(geolocationRequestTimeoutHandler) != 'undefined'){ clearTimeout(window['geolocationRequestTimeoutHandler']);//clear any previous timers } var timeout = timeoutThreshold || 30000;//30 seconds window['geolocationRequestTimeoutHandler'] = setTimeout('geolocationTimeoutHandler()', timeout);//set timeout handler navigator.geolocation.getCurrentPosition( function(position){ clearTimeout(window['geolocationRequestTimeoutHandler']); successHandler(position); }, function(error){ clearTimeout(window['geolocationRequestTimeoutHandler']); errorHandler(error); }, options ); }; function timeoutCallback(){ alert('Hi there! we are trying to locate you but you have not answered the security question yet.\n\nPlease choose "Share My Location" to enable us to find you.'); } function successCallback(position){ var msg = ''; msg += 'Success! you are at: '; msg += '\nLatitude: ' + position.coords.latitude; msg += '\nLongitude: ' + position.coords.longitude; msg += '\nAltitude: ' + position.coords.altitude; msg += '\nAccuracy: ' + position.coords.accuracy; msg += '\nHeading: ' + position.coords.heading; msg += '\nSpeed: ' + position.coords.speed; alert(msg); } function errorCallback(error){ if(error.PERMISSION_DENIED){ alert("User denied access!"); } else if(error.POSITION_UNAVAILABLE){ alert("You must be hiding in Area 51!"); } else if(error.TIMEOUT){ alert("hmmm we timed out trying to find where you are hiding!"); } } navigator.geolocation.requestCurrentPosition(successCallback, errorCallback, timeoutCallback, 7000, {maximumAge:10000, timeout:0}); </code></pre> <p>The concept is to set up a timer first (defaults to 30 seconds if not set). If the user doesn't do anything before the timer expires, a timeoutCallback is called.</p> <p><strong>Notes:</strong></p> <ol> <li>Some UI's (e.g. iPhone/iPad/iPod Safari) may make the Allow/Deny prompt modal - thus the user can't really continue until they pick something (I'd suggest to leave these users alone and let the default UI handle things</li> <li>If the user Allows the request (late), the timeout may still fire before the response comes back - I don't think there is anything you can do about this</li> <li>Code above is an example only... it needs cleaning up.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload