This topic has not yet been rated - Rate this topic

position object

[This documentation is preliminary and is subject to change.]

Provides geographic coordinates and other properties that represent a geographic location.

Internet Explorer 9

Standards information

There are no standards that apply here.

Remarks

The position object is passed as a parameter to the callback function defined for the getCurrentPosition function and the watchPosition function.

Windows Internet Explorer 9. The position object is only supported 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, which is passed as the position parameter of the successCallback function.


<!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>

 

 

Build date: 2/14/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ