Definition and Usage

The position property returns the position and altitude of the device on Earth.

Example

Get the longitude and latitude of the user's location:

var x = document.getElementById("demo");

function getLocation() {
if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(showPosition);
    else {
  } 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}
function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude + 
  "Longitude: " + position.coords.longitude; 
}

Try it yourself

position properties

Properties Description
position.coords Returns the Coordinates object defining the current position.
position.timestamp Returns the DOMTimeStamp object representing the time the position was retrieved.

Browser Support

Properties Chrome IE Firefox Safari Opera
position 5.0 9.0 3.5 5.0 16.0