HTML and CSS Reference
In-Depth Information
Table 7-2. PositionError Properties and Constants
Property/Constant
Description
PositionError.code
The code returned by the error; use the
following constants to determine the error
code
PositionError.PERMISSION_DENIED
The user rejected the request to get their
permission
PositionError.POSITION_UNAVAILABLE
The position could not be determined due to
some other device issue
PositionError.TIMEOUT
The position could not be determined, as
the request timed out
PositionError.message
The message from the error
You should use the PositionError constants PERMISSION_DENIED ,
POSITION_UNAVAILABLE , and TIMEOUT to handle the errors appropriately rather than
relying on the error message or comparing the error code to hard-coded
integers. The next code sample shows how errors should be handled using the
handleLocationError function and a switch statement.
var handleLocationError = function(error){
switch(error.code){
case error.PERMISSION_DENIED:
/**
* Handle permission denied response here,
* potentially display a dialog to the user
*/
var confirmed = confirm("We really need your location!");
if(confirmed){
navigator.getCurrentPosition(showCurrentPosition,
handleLocationError);
}
break;
case error.POSITON_UNAVAILABLE:
/**
* Handle position unavailable response here,
* potentially display a dialog to the user and
* ask them to enter their location manually
*/
var tryagain = confirm("Sorry, something serious is wrong, would
you like to try again?");
if(tryagain){
Search WWH ::




Custom Search