--- title: Geolocation.getCurrentPosition() slug: Web/API/Geolocation/getCurrentPosition tags: - API - Geolocation - Geolocation API - Method - Reference - Secure context - 위치 - 위치정보 translation_of: Web/API/Geolocation/getCurrentPosition ---
Geolocation.getCurrentPosition()
메서드는 장치의 현재 위치를 가져옵니다.
navigator.geolocation.getCurrentPosition(success[, error[, [options]])
success
error
{{optional_inline}}options
{{optional_inline}}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);
Specification | Status | Comment |
---|---|---|
{{SpecName('Geolocation')}} | {{Spec2('Geolocation')}} | Initial specification. |
{{Compat("api.Geolocation.getCurrentPosition")}}