JS geolocation(사용자위치)

Heewon👩🏻‍💻·2024년 4월 27일
function geoOk(position) {
  const lat = position.coords.latitude;
  const lng = position.coords.longitude;
  console.log("you live in ", lat, lng);
}

function geoError() {
  alert("we can't get your location!");
}

navigator.geolocation.getCurrentPosition(geoOk, geoError);

브라우저에서 좌표를 쏘게된다.

getCurrentPosition() < 마우스 커서 대면 2개의 arguments 를 요구하는걸 알수 있다. 1.success call back 2. error call back 두개 function만들어서 각 argument자리에 위치 시켜주면됨!

more about MDN Geolocation

profile
Interested in coding, meat lover, in love with dogs , enjoying everything happens in my life.

0개의 댓글