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 programmatically obtain the position of the device. It gives Web content access to the location of the device. This allows a Web site 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.
Properties
The Geolocation interface neither implements, nor inherits any property.
Methods
The Geolocation interface doesn't inherit any method.
Geolocation.getCurrentPosition()Secure context- Determines the device's current location and gives back a
GeolocationPositionobject with the data. Geolocation.watchPosition()Secure context- Returns a
longvalue 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().
Specifications
| Specification | Status | Comment |
|---|---|---|
| Geolocation API | Recommendation | Initial specification. |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Geolocation | Chrome Full support 5 | Edge Full support 12 | Firefox
Full support
3.5
| IE Full support 9 | Opera Full support 10.6 | Safari Full support 5 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 |
clearWatch | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 9 | Opera Full support 10.6 | Safari Full support 5 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 |
getCurrentPosition | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 9 | Opera Full support 10.6 | Safari Full support 5 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 |
| Secure context required | Chrome Full support 50 | Edge Full support ≤79 | Firefox Full support 55 | IE No support No | Opera Full support 37 | Safari Full support Yes | WebView Android
Full support
51
| Chrome Android Full support 50 | Firefox Android Full support 55 | Opera Android Full support 37 | Safari iOS Full support Yes | Samsung Internet Android Full support 5.0 |
watchPosition | Chrome Full support 5 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 9 | Opera Full support 10.6 | Safari Full support 5 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.
