This is where the PositionError argument of the PositionErrorCallback comes in handy. This object has two properties: code and message.
The code property can return three codes:
- 1: PERMISSION_DENIED
- 2: POSITION_UNAVAILABLE
- 3: TIMEOUT
Example
The codesnippet below only shows the part where I am handling the PositionErrorCallback. You can find the demo and full source here.
function onError(error){
var content = document.getElementById("content");
var message = "";
switch (error.code) {
case 0:
message = "Something went wrong: " + error.message;
break;
case 1:
message = "You denied permission to this page to retrieve a location.";
break;
case 2:
message = "The browser was unable to determine a location: " + error.message;
break;
case 3:
message = "The browser timed out before retrieving the location.";
break;
}
content.innerHTML = message;
}
No comments:
Post a Comment