Easy Tutorial
❮ Met Document Normalize Coll Datalist Options ❯

Navigator geolocation Property


Definition and Usage

The Navigator geolocation property returns a Geolocation object, which can be used to access the device's location information. This allows websites or applications to provide personalized results based on the user's location.

The geolocation property can only be used under HTTPS.

The geolocation position property can only be used after permission is granted.

Navigator geolocation is a read-only property.

For more information, refer to HTML5 Geolocation.

Syntax

navigator.geolocation

Browser Support

All major browsers support the geolocation property.

Chrome IE Edge Firefox Safari Opera
Yes Yes Yes Yes Yes Yes

Example

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;
}
❮ Met Document Normalize Coll Datalist Options ❯