Help us test MDN's new front-end: https://discourse.mozilla.org/t/help-us-test-mdns-new-react-front-end-beta/42593

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

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

구문

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

매개변수

success
Position 객체를 유일한 매개변수로 받는 콜백 함수.
error Optional
PositionError 객체를 유일한 매개변수로 받는 콜백 함수.
options Optional
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
Geolocation API Recommendation Initial specification.

브라우저 호환성

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
getCurrentPositionChrome Full support 5Edge Full support 12Firefox Full support 3.5IE Full support 9Opera Full support 16
Full support 16
No support 10.6 — 15
Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support 16
Full support 16
No support 11 — 14
Safari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

같이 보기

문서 태그 및 공헌자

이 페이지의 공헌자: alattalatta, mdnwebdocs-bot, fscholz, 3600s, khalid32, xcoda
최종 변경자: alattalatta,