하루를살자

JS Clone Project [Weather] - 1, getting location 본문

JS

JS Clone Project [Weather] - 1, getting location

Kai1996 2021. 12. 9. 17:12

Key Points

- use of navigator object and getCurrentPosition().

- Parameters of getCurrentPosition(). 

 

//if getCurrentPosition is succeed , it calls onGeoOk function with geolocation object information
function onGeoOk(pos){
    const lat = pos.coords.latitude; 
    const long = pos.coords.longitude;

    console.log(lat,long);

}

function onGeoError(){
    alert("Can't find you.!");
}

//getCurrentPosition requires 2 arugments, 1. successfull callback 2. fail callback
navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError);

 

Comments