카테고리 없음
[JavaScript] navigator() 를 이용해 현재 위치정보 불러오기
mswait
2022. 3. 3. 13:36
function onGeoOk(position) {
console.log(position);
}
function onGeoError() {
alert("Can't find you. No weather for you");
}
navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError);
우리가 공간만 주면 JavaScript 가 알아서 채워준다(position 이라는 인자를 준 것이 예)
20 년 전의 개발자는 이렇게 10줄의 코드만에 사용자의 위치정보를 알 수 없었다. 놀라운 일인것이다!