개발 => 복습 후 재정리 대기/JavsScript

[JavaScript] 위치 정보 읽기

장 상 현 2021. 5. 17.
const COORDS = 'coords';

function handleGeoSucces(position) {
    console.log(position);
}

function handleGeoError() {
    console.log("Can't access geo location");
}

function askForCoords() {
    navigator.geolocation.getCurrentPosition(handleGeoSucces, handleGeoError)
}

function loadCoords() {
    const loadedCoords = localStorage.getItem(COORDS);
    if ( loadedCoords === null ) {
        askForCoords();
    } else {

    }
}

function init() {
    loadCoords();
}

init();

html 파일에 추가!

<script src="weather.js"></script>

 

댓글