code property
Returns an integer value that indicates the type of error that occurred while trying to retrieve geographic information.
![]() ![]() |
Syntax
| JavaScript | |
|---|
Property values
Type: Integer
An Integer value corresponding to one of the following error conditions.
-
The user has denied permission for the website to access geographic information.
-
The request did not complete within the time allowed.
-
The geographic location could not be determined.
Standards information
- Geolocation API Specification, Section 5.5
Remarks
Windows Internet Explorer 9. This property is supported only for webpages displayed in IE9 Standards mode. For more information, see Defining Document Compatibility.
Examples
The following example shows an error callback function. The error parameter is a positionError object.
function errorCallback(error) { var message = ""; // Check for known errors switch (error.code) { case error.PERMISSION_DENIED: message = "This website does not have permission to use " + "the Geolocation API"; break; case error.POSITION_UNAVAILABLE: message = "The current position could not be determined."; break; case error.PERMISSION_DENIED_TIMEOUT: message = "The current position could not be determined " + "within the specified timeout period."; break; } // If it's an unknown error, build a message that includes // information that helps identify the situation, so that // the error handler can be updated. if (message == "") { var strErrorCode = error.code.toString(); message = "The position could not be determined due to " + "an unknown error (Code: " + strErrorCode + ")."; } console.log(message); }
See also
Show:

