Coordinates
A set of properties that describe the geographic coordinates of a position.
Properties
-
latitude: Latitude in decimal degrees. (Number)
-
longitude: Longitude in decimal degrees. (Number)
-
altitude: Height of the position in meters above the ellipsoid. (Number)
-
accuracy: Accuracy level of the latitude and longitude coordinates in meters. (Number)
-
altitudeAccuracy: Accuracy level of the altitude coordinate in meters. (Number)
-
heading: Direction of travel, specified in degrees counting clockwise relative to the true north. (Number)
-
speed: Current ground speed of the device, specified in meters per second. (Number)
Description
The Coordinates
object is attached to the [Position](../Position/position.html)
object that is
available to callback functions in requests for the current position.
Supported Platforms
- Android
- BlackBerry WebWorks (OS 5.0 and higher)
- iOS
- Tizen
- Windows Phone 7 and 8
- Windows 8
Quick Example
// onSuccess Callback
//
var onSuccess = function(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
};
// onError Callback
//
var onError = function() {
alert('onError!');
};
navigator.geolocation.getCurrentPosition(onSuccess, onError);
Full Example
<!DOCTYPE html>
<html>
<head>
<title>Geolocation Position Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// Display `Position` properties from the geolocation
//
function onSuccess(position) {
var div = document.getElementById('myDiv');
div.innerHTML = 'Latitude: ' + position.coords.latitude + '<br/>' +
'Longitude: ' + position.coords.longitude + '<br/>' +
'Altitude: ' + position.coords.altitude + '<br/>' +
'Accuracy: ' + position.coords.accuracy + '<br/>' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br/>' +
'Heading: ' + position.coords.heading + '<br/>' +
'Speed: ' + position.coords.speed + '<br/>';
}
// Show an alert if there is a problem getting the geolocation
//
function onError() {
alert('onError!');
}
</script>
</head>
<body>
<div id="myDiv"></div>
</body>
</html>
Android Quirks
altitudeAccuracy: Not supported by Android devices, returning null
.