JS) Geolocation.getCurrentPosition()

Ceciliaยท2022๋…„ 12์›” 26์ผ
0

JavaScript

๋ชฉ๋ก ๋ณด๊ธฐ
25/36
post-thumbnail

https://developer.mozilla.org/ko/docs/Web/API/Geolocation_API/Using_the_Geolocation_API

https://developer.mozilla.org/ko/docs/Web/API/Geolocation/getCurrentPosition




Geolocation.getCurrentPosition()


์žฅ์น˜์˜ ํ˜„์žฌ ์œ„์น˜๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

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

coords = ์ขŒํ‘œ
latitude = ์œ„๋„
longitude = ๊ฒฝ๋„

profile
'์ด๊ฒŒ ์ตœ์„ ์ผ๊นŒ?'๋ผ๋Š” ๊ณ ์ฐฐ์„ ํ†ตํ•ด ๋์—†์ด ์„ฑ์žฅํ•˜๊ณ , ๊ทธ ๊ณผ์ •์„ ์ฆ๊ธฐ๋Š” ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž์˜ ์ž…์žฅ์„ ์ƒ๊ฐํ•˜๋ฉฐ ์ตœ์„ ์˜ ํŽธ์˜์„ฑ์„ ์ฐพ๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€