coords property

Gets a reference to a coordinates object that contains geographic information returned by the getCurrentPosition or watchPosition functions.

Geolocation API Specification, Section 5.3Internet Explorer 9

 

Syntax

JavaScript

p = object.coords

 

Property values

Type: Object

A reference to the a coordinates object representing the geographic location, including latitude, longitude, and accuracy of the location data.

Standards information

Remarks

The position is passed as a parameter to the callback function defined with the getCurrentPosition function or the watchPosition function.

Windows Internet Explorer 9. This property is supported only for webpages displayed in IE9 Standards mode. For more information, see Defining Document Compatibility.

Examples

The following example shows how to access the position object in the successCallback function. In this example, this object is named position.


<!DOCTYPE html>  
<html>
<head>
<title>Requesting Location</title>
<script type="text/javascript">
function setText(val, e) {
    document.getElementById(e).value = val;
}
function insertText(val, e) {
    document.getElementById(e).value += val;
}
var nav = null; 
function requestPosition() {
  if (nav == null) {
      nav = window.navigator;
  }
  if (nav != null) {
      var geoloc = nav.geolocation;
      if (geoloc != null) {
          geoloc.getCurrentPosition(successCallback);
      }
      else {
          alert("geolocation not supported");
      }
  }
  else {
      alert("Navigator not found");
  }
}
 
function successCallback(position)
{
   setText(position.coords.latitude, "latitude");
   setText(position.coords.longitude, "longitude");
}
</script>
</head>
<body>
<label for="latitude">Latitude: </label><input id="latitude" /> <br />
<label for="longitude">Longitude: </label><input id="longitude" /> <br />
<input type="button" onclick="requestPosition()" value="Get Latitude and Longitude"  /> 
</body>
</html>

See also

position

 

 

Show: