Widely availableHelpful when location materially improves the task, but it should always remain optional and transparent.

Overview

The Geolocation API allows a page to request the user’s current position. It is useful for nearby search, local context, and map-based features.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
5
12
3.5
5
18
≤3

The clearWatch() method of the Geolocation interface is used to unregister location/error monitoring handlers previously installed using Geolocation.watchPosition().

5
12
3.5
5
18
≤3

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

5
12
3.5
5
18
≤3
secure_context_required

Secure context required

50
79
55
10
50
10

The watchPosition() method of the Geolocation interface is used to register a handler function that will be called automatically each time the position of the device changes. You can also, optionally, specify an error handling callback function.

5
12
3.5
5
18
≤3

The GeolocationCoordinates interface represents the position and altitude of the device on Earth, as well as the accuracy with which these properties are calculated. The geographic position information is provided in terms of World Geodetic System coordinates (WGS84).

79
79
72
13.1
79
13.4

The accuracy read-only property of the GeolocationCoordinates interface is a strictly positive double representing the accuracy, with a 95% confidence level, of the GeolocationCoordinates.latitude and GeolocationCoordinates.longitude properties expressed in meters.

5
12
3.5
5
18
≤3

The altitude read-only property of the GeolocationCoordinates interface is a double representing the altitude of the position in meters above the WGS84 ellipsoid (which defines the nominal sea level surface). This value is null if the implementation cannot provide this data.

5
12
3.5
5
18
≤3

The altitudeAccuracy read-only property of the GeolocationCoordinates interface is a strictly positive double representing the accuracy, with a 95% confidence level, of the altitude expressed in meters. This value is null if the implementation doesn't support measuring altitude.

5
12
3.5
5
18
≤3

The heading read-only property of the GeolocationCoordinates interface is a double representing the direction in which the device is traveling. This value, specified in degrees, indicates how far off from heading due north the device is. 0 degrees represents true north, and the direction is determined clockwise (which means that east is 90 degrees and west…

5
12
3.5
5
18
≤3

The latitude read-only property of the GeolocationCoordinates interface is a double representing the latitude of the position in decimal degrees.

5
12
3.5
5
18
≤3

The longitude read-only property of the GeolocationCoordinates interface is a number which represents the longitude of a geographical position, specified in decimal degrees. Together with a timestamp, given as Unix time in milliseconds, indicating a time of measurement, the GeolocationCoordinates object is part of the GeolocationPosition interface, which is…

5
12
3.5
5
18
≤3
secure_context_required

Secure context required

47
79
55
10
47
10

The speed read-only property of the GeolocationCoordinates interface is a double representing the velocity of the device in meters per second. This value is null if the implementation is not able to measure it.

5
12
3.5
5
18
≤3

The toJSON() method of the GeolocationCoordinates interface is a Serialization; it returns a JSON representation of the GeolocationCoordinates object.

126
126
129
18
126
18

The GeolocationPosition interface represents the position of the concerned device at a given time. The position, represented by a GeolocationCoordinates object, comprehends the 2D position of the device, on a spheroid representing the Earth, but also its altitude and its speed.

79
79
72
13.1
79
13.4

The coords read-only property of the GeolocationPosition interface returns a GeolocationCoordinates object representing a geographic position. It contains the location, that is longitude and latitude on the Earth, the altitude, and the speed of the object concerned, regrouped inside the returned value. It also contains accuracy information about these…

5
12
3.5
5
18
≤3
secure_context_required

Secure context required

47
≤18
55
10
47
10

The timestamp read-only property of the GeolocationPosition interface represents the date and time that the position was acquired by the device.

5
12
3.5
5
18
≤3

The toJSON() method of the GeolocationPosition interface is a Serialization; it returns a JSON representation of the GeolocationPosition object.

126
126
129
18
126
18

The GeolocationPositionError interface represents the reason of an error occurring when using the geolocating device.

79
79
72
13.1
79
13.4

The code read-only property of the GeolocationPositionError interface is an unsigned short representing the error code.

5
12
3.5
5
18
4.2

The message read-only property of the GeolocationPositionError interface returns a human-readable string describing the details of the error.

5
12
3.5
5
18
4.2
secure_context_required

Secure context required

47
≤18
55
10
47
10

The Navigator.geolocation read-only property returns a Geolocation object that 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.

5
12
3.5
5
18
≤3
geolocation (secure context required)

Secure context required

47
79
55
10
47
10
permission_geolocation

`geolocation` permission

43
79
46
16
43
16
Other
html.elements.iframe.allow.geolocation
64
79
74
64

The HTTP Permissions-Policy header geolocation directive controls whether the current document is allowed to use the Geolocation Interface.

88
88
88
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 1 item(s)
Implementation note
  • GPSD (GPS daemon) support added in Firefox 3.6. WiFi-based location is provided by Google (privacy) or a custom provider (MLS instructions).
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (78)
Implementation note
  • Previously available under a different name: Coordinates (5)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (79)
Implementation note
  • Previously available under a different name: Coordinates (12)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (71)
Implementation note
  • Previously available under a different name: Coordinates (3.5)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (13.1)
Implementation note
  • Previously available under a different name: Coordinates (5)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (78)
Implementation note
  • Previously available under a different name: Coordinates (18)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (13.4)
Implementation note
  • Previously available under a different name: Coordinates (≤3)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (78)
Implementation note
  • Previously available under a different name: Position (5)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (79)
Implementation note
  • Previously available under a different name: Position (12)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (71)
Implementation note
  • Previously available under a different name: Position (3.5)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (13.1)
Implementation note
  • Previously available under a different name: Position (5)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (78)
Implementation note
  • Previously available under a different name: Position (18)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (13.4)
Implementation note
  • Previously available under a different name: Position (≤3)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (79)
Implementation note
  • Previously available under a different name: PositionError (5)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (79)
Implementation note
  • Previously available under a different name: PositionError (12)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (71)
Implementation note
  • Previously available under a different name: PositionError (3.5)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: PositionError (5)
Notes 2 item(s)
Removed
  • This feature was removed in a later browser version (79)
Implementation note
  • Previously available under a different name: PositionError (18)
Notes 1 item(s)
Implementation note
  • Previously available under a different name: PositionError (4.2)

Syntax

JAVASCRIPT
navigator.geolocation.getCurrentPosition(
  (pos) => {
    console.log('Latitude:', pos.coords.latitude);
    console.log('Longitude:', pos.coords.longitude);
  },
  (err) => console.error('Location error:', err.message),
  { enableHighAccuracy: true }
);

Use cases

  • Nearby results

    Find nearby stores, services, or content tailored to the user’s current area.

  • Map convenience

    Center maps or directions around the user’s current position when they explicitly request it.

Cautions

  • Location access is sensitive and should never be requested before the benefit is clear to the user.
  • Permission denial and low-accuracy results must be handled gracefully.

Accessibility

  • Explain why location is requested and provide a manual alternative when the feature can still work without it.

Powered by web-features