Weather
8.0 Geolocation
1. function <navigator>
navigator.geolocation.getCurrentPosition()
1) getCurrentPosition(argument1, argument2)
(argument1) the function that will be called if everything is okay.
(argument2) the function that will be called if there is an error.
2) Declare function for getCurrentPosition
function onGoeOk(){}, functiononGeoError(){}
if its okay -> console.log "You live in 위도, 경도 "
if error -> execute alert
2. Need to use the service going to take this sort of numbers and turn them into a location
-> https://openweathermap.org/api
Weather API - OpenWeatherMap
openweathermap.org
8.1 Weather API
1)
https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid=
2) How to call url from Javascript
(1) make valuable
- const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}`
(2) units
- default temp. is using Fahrenheit, If you want to change it put &units=metric on the url
3) get the url using fetch
fetch(url) -> you don't have to go to the url, Javascript will call the url.
fetch(url).then(response => response.json()).then(data => {
const name = data.name;
const weather = data.weather[0].main;
})
** Error
4) make a div on the html
5) modify fetch