Hello, I’m challenging for Weather app now.
I could show ‘Location’ through API but ‘Weather’ and ‘Temperature’ through API does not show up.
Could anybody give me advice? Thank you so much in advance.
HTML
<div class="container">
<h1> Show you the weahter </h1>
<span id="location"> </span>
<span id="weather"> </span>
<span id="temp"></span>
</div>
Javascript
var OpenWeatherKey = '4178c7c00c8613f9b84c4784af4fff3e';
var locationUrl = 'http://freegeoip.net/json/';
function getLocation(){
$.ajax({
url : locationUrl,
dataType: "json",
success : function(data){
var country = data['country_name'];
var city = data['city'];
var latitude = data['latitude'];
var longitude = data['longitude'];
$('#location').html(city + ', ' + country);
var Weather = "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&units=" + tempUnit + "&APPID=" +OpenWeatherKey;
getWeather(Weather);
console.log(Weather);
}
});
}
function getWeather(url){
$.ajax({
url:url,
dataType:"json",
success: function(data){
var weather = data['weather'][0]['main'];
var temp = data['main']['temp'];
$('#weather').html(weather);
$('#temp').html(temp);
}
});
}
getLocation();