Geolocation getCurrentPosition() Method

Definition and Usage

getCurrentPosition() Method returns the current position of the device.

example

Get the longitude and latitude of the user's location:

var x = document.getElementById("demo");
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    x.innerHTML = "This browser does not support geolocation.";
  }
}
function showPosition(position) {
  x.innerHTML = "latitude: " + position.coords.latitude +
  "<br>longitude: " + position.coords.longitude;
}

try it yourself

syntax

navigator.geolocation.getCurrentPosition(success, error, options)

parameter

parameter description
success required. Call back function with Position object as its only input parameter.
error choosable. Call back function with PositionError object as its only input parameter.
options ਵਿਕਲਪਿਤ।PositionOptions ਪੰਜਾਬੀ

ਵਾਪਸੀ ਮੁੱਲ

ਉਪਕਰਣ ਦੀ ਮੌਜੂਦਾ ਸਥਿਤੀ。

ਬਰਾਉਜ਼ਰ ਸਮਰਥਨ

ਚਰਾਮ ਐਜ਼ ਫਾਇਰਫਾਕਸ ਸੈਫਾਰੀ ਓਪੇਰਾ
ਚਰਾਮ ਐਜ਼ ਫਾਇਰਫਾਕਸ ਸੈਫਾਰੀ ਓਪੇਰਾ
5.0 9.0 3.5 5.0 16.0