diff --git a/SalahWatchFace.wgt b/SalahWatchFace.wgt index 8c662a7..feab17e 100644 Binary files a/SalahWatchFace.wgt and b/SalahWatchFace.wgt differ diff --git a/data/weather.json b/data/weather.json deleted file mode 100644 index 173efc3..0000000 --- a/data/weather.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "url": "google.com" -} \ No newline at end of file diff --git a/index.html b/index.html index d4c7fd9..af83db2 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,7 @@
-
23ยบ
+
..
..
diff --git a/js/app.js b/js/app.js index f959842..b51ec68 100644 --- a/js/app.js +++ b/js/app.js @@ -92,14 +92,14 @@ return urlWithParams; } - function updateSalah({ lat, long }) { + function updateSalah({ lat, lon }) { var salahText = document.querySelector('#salah-status'); salahText.innerHTML = "Updating.."; var req = new XMLHttpRequest(); var apiURL = addParamsToUrl('http://api.aladhan.com/v1/calendar', { latitude: lat, - longitude: long, + longitude: lon, school: 1 }); @@ -160,8 +160,34 @@ * @param {{number}} lat the latitude of the geolocation. * @param {{number}} long the longitude of the geolocation. */ - function updateWeather({lat, long}) { + function updateWeather({lat, lon}) { + var weatherText = document.querySelector('#weather-text'); + //make api request to some weather api using coordinates + var req = new XMLHttpRequest(); + var apiURL = addParamsToUrl('http://api.openweathermap.org/data/2.5/weather', { + lat, lon, + appid: '42adc1f5752b2d26823d3349379d0339' + }); + + req.overrideMimeType("application/json"); + req.open("GET", apiURL, false); + req.onreadystatechange = function () { + if (req.responseText) { + var res = JSON.parse(req.responseText) + var weather = res.weather[0].main; + var temp = convertTemp(res.main.temp); + weatherText.innerHTML = weather + ' ' + temp + '\u00B0F'; + } else { + weatherText.innerHTML = ':('; + } + } + req.send(); + } + + function convertTemp(k = 0){ + //Fahrenheit + return (1.8 * (k - 273) + 32).toFixed(1); } /** @@ -185,7 +211,7 @@ } /** - * Update weather and air pollution information. + * Update salah, weather information. * If can't get location information, displays no GPS icon. * @private */ @@ -194,12 +220,12 @@ function (pos) { updateSalah({ lat: pos.coords.latitude, - long: pos.coords.longitude + lon: pos.coords.longitude + }); + updateWeather({ + lat: pos.coords.latitude, + lon: pos.coords.longitude }); - // updateWeather({ - // lat: pos.coords.latitude, - // long: pos.coords.longitude - // }); } ); }