Definition and Usage
- Previous Page getCurrentPosition()
- Next Page coordinates
- Go Back to the Previous Level Geolocation Object
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; }
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 |
- Previous Page getCurrentPosition()
- Next Page coordinates
- Go Back to the Previous Level Geolocation Object