Geolocation position attribute
- Föregående sida getCurrentPosition()
- Nästa sida koordinater
- Gå tillbaka till föregående nivå Geolocation-objekt
Definition and Usage
The position attribute returns the location 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 + "<br>Longitude: " + position.coords.longitude; }
position attribute
egenskaper | Description |
---|---|
position.coords | Return the Coordinates object defining the current position. |
position.timestamp | Return the DOMTimeStamp object representing the time the position was retrieved. |
Webbläsarstöd
egenskaper | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
position | 5.0 | 9.0 | 3.5 | 5.0 | 16.0 |
- Föregående sida getCurrentPosition()
- Nästa sida koordinater
- Gå tillbaka till föregående nivå Geolocation-objekt