--- title: Geolocation.getCurrentPosition() slug: Web/API/Geolocation/getCurrentPosition translation_of: Web/API/Geolocation/getCurrentPosition ---
{{ APIRef("Geolocation API") }}
O método Geolocation.getCurrentPosition() é utilizado para capturar a posição atual do dispositivo.
navigator.geolocation.getCurrentPosition(success, error, options)
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ção | Estado | Comentário |
|---|---|---|
| {{SpecName('Geolocation')}} | {{Spec2('Geolocation')}} | Especificação inicial. |
{{ CompatibilityTable() }}
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Suporte básico | 5 | {{CompatGeckoDesktop("1.9.1")}} | 9 | 10.60 Removido no 15.0 Reintroduzido no 16.0 |
5 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Suporte básico | {{CompatUnknown()}} | {{CompatUnknown()}} | {{CompatGeckoMobile("4")}} | {{CompatUnknown()}} | 10.60 | {{CompatUnknown()}} |