Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
Leandro committed May 19, 2019
1 parent 7bdf79d commit 15f8e23
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions js/localweather.js
Original file line number Diff line number Diff line change
@@ -20,33 +20,34 @@ function getGeoInfo() {
}


function getWeatherInfo(lat, lon) {
async function getWeatherInfo(lat, lon) {
const OWMKEY = "9e63e3db08ca3fc65ea3925879bdc7b7";
const OWMAPI = "https://api.openweathermap.org/data/2.5/weather";

try {
let data = await $.ajax({
url: OWMAPI,
data: {
lat: lat,
lon: lon,
units: 'metric',
appid: OWMKEY
},
dataType: 'json'
});

$.ajax({
url: OWMAPI,
data: {
lat: lat,
lon: lon,
units: 'metric',
appid: OWMKEY
},
dataType: 'json',
success: function(data) {
let loc = data.name;
let icon = "https://openweathermap.org/img/w/" + data.weather[0].icon + ".png";
let temp = data.main.temp;
let weather = data.weather[0].description;
weather = weather.substr(0, 1).toUpperCase() + weather.substr(1);
let wind = data.wind.speed;

displayWeather(loc, icon, weather, temp, wind);
},
error: function(dataErr) {
alert("Weather data not available due to " + dataErr.statusText);
}
});
let loc = data.name;
let icon = "https://openweathermap.org/img/w/" + data.weather[0].icon + ".png";
let temp = data.main.temp;
let weather = data.weather[0].description;
weather = weather.substr(0, 1).toUpperCase() + weather.substr(1);
let wind = data.wind.speed;

displayWeather(loc, icon, weather, temp, wind);

} catch (ex) {
alert(`An error has occurred.\nPlease try again later.`);
}
}


0 comments on commit 15f8e23

Please sign in to comment.