/Web APIs


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

The Geolocation interface represents an object able to obtain the position of the device programmatically. It gives Web content access to the location of the device. This allows a website or app to offer customized results based on the user's location.

An object with this interface is obtained using the navigator.geolocation property implemented by the Navigator object.

Note: For security reasons, when a web page tries to access location information, the user is notified and asked to grant permission. Be aware that each browser has its own policies and methods for requesting this permission.

Instance properties

The Geolocation interface neither implements, nor inherits any property.

Instance methods

The Geolocation interface doesn't inherit any method.

Geolocation.getCurrentPosition() Secure context

Determines the device's current location and gives back a GeolocationPosition object with the data.

Geolocation.watchPosition() Secure context

Returns a long value representing the newly established callback function to be invoked whenever the device location changes.

Geolocation.clearWatch() Secure context

Removes the particular handler previously installed using watchPosition().


Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Geolocation 5 12
3.5GPSD (GPS daemon) support added in Firefox 3.6. WiFi-based location is provided by Google (privacy) or a custom provider (MLS instructions).
9 10.6 5 ≤37 18 4 11 ≤3 1.0
clearWatch 5 12 3.5 9 10.6 5 ≤37 18 4 11 ≤3 1.0
getCurrentPosition 5 12 3.5 9 10.6 5 ≤37 18 4 11 ≤3 1.0
secure_context_required 50 79 55 No 37 10
51Secure context is only required for applications targeting Android Nougat (7) and higher. See bug 603574.
50 55 37 10 5.0
watchPosition 5 12 3.5 9 10.6 5 ≤37 18 4 11 ≤3 1.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.