--- 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 |