-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
25 lines (21 loc) · 756 Bytes
/
main.js
File metadata and controls
25 lines (21 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function startup() {
// ganti apiKey dengan key yang didapat dari dashboard openweather
const api_key = apiKey;
// ganti latitude dengan latitude lokasi sembarang
const lat = latitude;
// ganti longitude dengan lotitude lokasi sembarang
const lon = longitude;
const cuaca = document.getElementById("cuaca");
const suhu = document.getElementById("suhu");
axios
.get(
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&lang=id&units=metric&appid=${api_key}`
)
.then(function (response) {
console.log(response.data);
const weather = response.data.weather;
cuaca.innerHTML = weather[0].description;
const temp = response.data.main;
suhu.innerHTML = temp.temp;
});
}