Home

getCurrentPosition

getCurrentPosition is a method of the Geolocation interface in the Web Geolocation API. It retrieves the device’s current geographic position and delivers it to a success callback if the position can be determined. The call is asynchronous and may fail for various reasons, in which case an error callback is invoked.

Parameters:

- successCallback: a function that is called with a Position object when the location is obtained. The

- errorCallback (optional): a function that is called with a PositionError object if the location cannot be

- options (optional): an object with properties to influence the request. Common options are enableHighAccuracy (boolean), timeout

Behavior and considerations:

- The method does not return a value; it relies on callbacks to provide results.

- Location data may be sourced from GPS, Wi‑Fi, or other sensors, depending on device capability and

- Permission is typically required; the user may be prompted to grant access to location data.

- The request may time out or be denied, depending on device, browser, and user decision.

- Secure origins (HTTPS) are usually required for geolocation to function.

See also:

- Geolocation API, Position, Coordinates.

Position
includes
a
Coordinates
object
with
latitude,
longitude,
accuracy,
and
optionally
altitude,
altitudeAccuracy,
heading,
and
speed,
along
with
a
timestamp.
determined.
The
error
includes
a
code
(such
as
PERMISSION_DENIED,
POSITION_UNAVAILABLE,
or
TIMEOUT)
and
a
message.
(milliseconds
to
wait
before
failing),
and
maximumAge
(milliseconds
to
accept
cached
positions).
user
settings.