coderef

Geolocation APIBaseline · Widely available

The navigator.geolocation API requests the user's latitude, longitude, heading, and speed.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.

Browser support

DesktopChrome
1–4Not supported
5+Supportedsince May 25, 2010
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–3Not supported
3.5+Supportedsince Jun 30, 2009
Current: 157
Safari
1–4Not supported
5+Supportedsince Jun 7, 2010
Current: 27
MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155
Firefox Android
4+Supportedsince Mar 29, 2011
Current: 157
Safari iOS
1–2Not supported
≤3+Supportedsince Jun 17, 2009
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: Geolocation.

Feature detection

JS · check before using
if ("Geolocation" in globalThis) {
  // Geolocation is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (29). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Geolocation5123.55184≤3
Geolocation.clearWatch5123.55184≤3
Geolocation.getCurrentPosition5123.55184≤3
Geolocation.secure_context_required50795510505510
Geolocation.watchPosition5123.55184≤3
GeolocationCoordinates79797213.1797913.4
GeolocationCoordinates.accuracy79797213.1797913.4
GeolocationCoordinates.altitude79797213.1797913.4
GeolocationCoordinates.altitudeAccuracy79797213.1797913.4
GeolocationCoordinates.heading79797213.1797913.4
GeolocationCoordinates.latitude79797213.1797913.4
GeolocationCoordinates.longitude79797213.1797913.4
GeolocationCoordinates.secure_context_required79797213.1797913.4
GeolocationCoordinates.speed79797213.1797913.4
GeolocationCoordinates.toJSON1261261291812612918
GeolocationPosition79797213.1797913.4
GeolocationPosition.coords79797213.1797913.4
GeolocationPosition.secure_context_required79797213.1797913.4
GeolocationPosition.timestamp79797213.1797913.4
GeolocationPosition.toJSON1261261291812612918
Show 9 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
GeolocationPositionError79797213.1797913.4
GeolocationPositionError.code79797213.1797913.4
GeolocationPositionError.message79797213.1797913.4
GeolocationPositionError.secure_context_required79797213.1797913.4
Navigator.geolocation5123.55184≤3
Navigator.geolocation.secure_context_required47795510475510
Permissions.permission_geolocation43794616434616
iframe.allow.geolocation647974✕6479✕
http.headers.Permissions-Policy.geolocation8888✕✕88✕✕