Geolocation Coordinates Attribute
- Previous Page coordinates
- Next Page getCurrentPosition()
- Go to the Previous Level Geolocation Object
The coordinates attribute returns the position and height of the device on Earth.
Example
Get the user's location coordinates:
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; }
Coordinates attribute
Properties | Description |
---|---|
coordinates.latitude | Return the latitude of the location, in decimal degrees. |
coordinates.longitude | Return the longitude of the location, in decimal degrees. |
coordinates.altitude | Return the height of the location, relative to sea level, in meters. |
coordinates.accuracy | Return the precision of the latitude and longitude attributes, in meters. |
coordinates.altitudeAccuracy | Return the precision of the altitude attribute, in meters. |
coordinates.heading | Return the direction of movement of the device. The value is in degrees, indicating how far the device is from the north direction. 0 degrees represents true north, with the direction being clockwise (east is 90 degrees, west is 270 degrees). If the speed is 0, then heading is NaN. If the device cannot provide heading information, then this value is null. |
coordinates.speed | Return the speed of the device, in meters per second. This value can be null. |
Browser Support
Properties | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
coordinates | 5.0 | 9.0 | 3.5 | 5.0 | 10.6 |
- Previous Page coordinates
- Next Page getCurrentPosition()
- Go to the Previous Level Geolocation Object