Geolocation.getCurrentPosition()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
O método Geolocation.getCurrentPosition()
é utilizado para capturar a posição atual do dispositivo.
Sintaxe
navigator.geolocation.getCurrentPosition(success, error, options)
Parâmetros
- success
-
Uma função de retorno que captura um objeto
Position
como seu parâmetro de entrada. - error Optional
-
Uma função de retorno opcional que captura um objeto
PositionError
como seu parâmetro de entrada. - options Optional
-
Um objeto opcional
PositionOptions
.
Exemplo
js
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0,
};
function success(pos) {
var crd = pos.coords;
console.log("Sua posição atual é:");
console.log("Latitude : " + crd.latitude);
console.log("Longitude: " + crd.longitude);
console.log("Mais ou menos " + crd.accuracy + " metros.");
}
function error(err) {
console.warn("ERROR(" + err.code + "): " + err.message);
}
navigator.geolocation.getCurrentPosition(success, error, options);
Especificações
Specification |
---|
Geolocation # getcurrentposition-method |
Compatibilidade com navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getCurrentPosition |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.