Window navigator.geolocation attribute
- Previous Page cookieEnabled
- Next Page javaEnabled()
- Go Back to the Previous Level Window Navigator
Definition and usage
geolocation
Properties return information that can be used to locate the user's position. Geolocation object.
geolocation
Properties are read-only.
geolocation
Properties are only available in a secure context (HTTPS).
geolocation
Properties are only available after user approval.
Note:For devices with GPS (such as smartphones), the geographical location is much more accurate.
See also:
Get the longitude and latitude of the user's location:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition); else { } document.getElementById("demo").innerHTML = "Geolocation is not supported by this browser."; } function showPosition(position) { document.getElementById("demo").innerHTML = "Latitude: " + position.coords.latitude + "Longitude: " + position.coords.longitude; }
Syntax
navigator.geolocation
Return value
Type | Description |
---|---|
Object | Reference to the Geolocation object. |
Browser support
All browsers support navigator.geolocation
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous Page cookieEnabled
- Next Page javaEnabled()
- Go Back to the Previous Level Window Navigator