--- title: Geolocation.getCurrentPosition() slug: Web/API/Geolocation/getCurrentPosition translation_of: Web/API/Geolocation/getCurrentPosition ---
{{ APIref("Geolocation API") }}
El método Geolocation.getCurrentPosition()
se utiliza para obtener la posición de un dispositivo.
navigator.geolocation.getCurrentPosition(success, error, options)
var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; function success(pos) { var crd = pos.coords; console.log('Your current position is:'); console.log('Latitude : ' + crd.latitude); console.log('Longitude: ' + crd.longitude); console.log('More or less ' + crd.accuracy + ' meters.'); }; function error(err) { console.warn('ERROR(' + err.code + '): ' + err.message); }; navigator.geolocation.getCurrentPosition(success, error, options);
Especificación | Estado | Comentario |
---|---|---|
{{SpecName('Geolocation')}} | {{Spec2('Geolocation')}} | Especificación inicial |
{{ CompatibilityTable() }}
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Soporte básico | 5 | {{CompatGeckoDesktop("1.9.1")}} | 9 | 10.60 Eliminado en 15.0 Reintroducido en 16.0 |
5 |
Característica | Android | Chrome para Android | Firefox Mobil (Gecko) | IE Mobile | Opera Mobil | Safari Mobile |
---|---|---|---|---|---|---|
Soporte básico | {{CompatUnknown()}} | {{CompatUnknown()}} | {{CompatGeckoMobile("4")}} | {{CompatUnknown()}} | 10.60 | {{CompatUnknown()}} |