Geolocation

April 01, 2021

Geolocation

Logic

사용자의 현재 위치를 가져오는 Geolocation API를 이용한다.

<script>
  const arrow = document.querySelector('.arrow')
  const speed = document.querySelector('.speed-value')

  navigator.geolocation.watchPosition((data) => {
    console.log(data)
    speed.textContent = data.coords.speed
    arrow.style.transform = `rotate(${data.coords.heading}deg)`
  }, (err) => {
    console.error(err)
  })
</script>

JavaScript

  • navigator.geolocation.getCurrentPosition(success[, error[, [options]]): 장치의 현재 위치를 가져온다.
  • GeolocationPosition 인터페이스는 주어진 시간에 장치가 위치한 지점을 나타낸다.

Profile picture

Written by Soomin 호기심이라는 우주선을 타고 떠나는 여행. 이 곳은 모험을 기록하는 우주정거장. Soomin Space Station