Geolocation: getCurrentPosition() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The getCurrentPosition() method of the Geolocation interface is used to get the current position of the device.

Note that in addition to requiring a secure context this feature may be blocked by the geolocation Permissions-Policy, and also requires that explicit permission be granted by the user. If required, the user will be prompted when this method is called. The permission state can be queried using the geolocation user permission in the Permissions API.

Syntax

js
getCurrentPosition(success)
getCurrentPosition(success, error)
getCurrentPosition(success, error, options)

Parameters

success

A callback function that takes a