--- title: Geolocation.getCurrentPosition() slug: Web/API/Geolocation/getCurrentPosition tags: - API - Geolocation - Geolocation API - Method - Reference - Secure context - 위치 - 위치정보 translation_of: Web/API/Geolocation/getCurrentPosition ---
{{securecontext_header}}{{ APIRef("Geolocation API") }}

Geolocation.getCurrentPosition() 메서드는 장치의 현재 위치를 가져옵니다.

구문

navigator.geolocation.getCurrentPosition(success[, error[, [options]])

매개변수

success
{{domxref("GeolocationPosition")}} 객체를 유일한 매개변수로 받는 콜백 함수.
error {{optional_inline}}
{{domxref("GeolocationPositionError")}} 객체를 유일한 매개변수로 받는 콜백 함수.
options {{optional_inline}}
{{domxref("PositionOptions")}} 객체.

예제

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")}}

같이 보기