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.
The Geolocation
interface neither implements, nor inherits any property.
The Geolocation
interface doesn't inherit any method.
Geolocation.getCurrentPosition()
Secure context
Position
object with the data.Geolocation.watchPosition()
Secure context
long
value representing the newly established callback function to be invoked whenever the device location changes.Geolocation.clearWatch()
Secure context
watchPosition()
.Specification | Status | Comment |
---|---|---|
Geolocation API | Recommendation | Initial specification. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 5 | 12 | 3.5
|
9 | 16
|
5 |
Secure context required | 50 | ? | 55 | No | 37 | Yes |
clearWatch |
5 | Yes | 3.5 | 9 | 16
|
Yes |
getCurrentPosition |
5 | Yes | 3.5 | 9 | 16
|
Yes |
watchPosition |
5 | Yes | 3.5 | 9 | 16
|
Yes |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | 12 | 4 | 15 | Yes | Yes |
Secure context required | 51
|
50 | ? | 55 | 37 | Yes | ? |
clearWatch |
Yes | Yes | Yes | 4 | 15 | Yes | Yes |
getCurrentPosition |
Yes | Yes | Yes | 4 | 15 | Yes | Yes |
watchPosition |
Yes | ? | Yes | 4 | 15 | Yes | Yes |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation