HTML DOM geolocation coordinates attribute is used to obtain the location and altitude of the user device on the earth. The user must approve the coordinates he wants to provide for this property to work. This is done so as not to compromise user privacy. This can be used to track the location of various devices.
The following are the coordinate properties -
Note - All these properties are read-only and have a return type of double.
Sr.No th> | Properties and Description |
---|---|
1 |
coordinates.latitude Returns the latitude of the device location in decimal degrees. |
2 |
Coordinates.Longitude Returns the longitude of the device location in decimal degrees |
3 |
coefficients.altitude Returns the location's altitude in meters, relative to sea level. Can return null if there is no GPS in the device. |
4 |
Coordinates. Accuracy Returns the accuracy of the latitude and longitude attributes in meters |
coordinates.altitudeAccuracy Returns the accuracy of the altitude attribute in meters |
|
cocos.headingReturn the direction of travel of the device. This value, in degrees, represents the device's distance from a heading due north. 0 degrees represents true north, and the direction is determined clockwise (east is 90 degrees, west is 270 degrees). If the speed is 0, the heading is NaN. If the device cannot provide heading information, the value is null | |
Coordinates.speed Returns the speed of the device (in meters per second). The value can be null. |
coordinates.property
<!DOCTYPE html> <html> <body> <h1>Geolocation coordinates property</h1> <p>Get you coordinates by clicking the below button</p> <button onclick="getCoords()">COORDINATES</button> <p id="Sample">Your coordinates are:</p> <script> var p = document.getElementById("Sample"); function getCoords() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showCoords); } else { p.innerHTML ="This browser doesn't support geolocation."; } } function showCoords(position) { p.innerHTML = "Longitude:" + position.coords.longitude + "<br>Latitude: " + position.coords.latitude+"<br>Accuracy: "+ position.coords.accuracy; } </script> </body> </html>
<button onclick="getCoords()">COORDINATES</button>
function getCoords() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showCoords); } else { p.innerHTML ="This browser doesn't support geolocation."; } } function showCoords(position) { p.innerHTML = "Longitude:" + position.coords.longitude + "<br>Latitude: " + position.coords.latitude+"<br>Accuracy: "+ position.coords.accuracy; }
The above is the detailed content of HTML DOM Geolocation coordinates attribute. For more information, please follow other related articles on the PHP Chinese website!