Hello everyone!
I’m working on Show the Local Weather challenge.
How can I get temperature of my location from the Open Weather Map?
Here’s my code below.
function weather() {
var location = document.getElementById("location");
var apiKey = '****************************************';
var url = 'http://api.openweathermap.org/data/2.5/weather';
navigator.geolocation.getCurrentPosition(success, error);
function success(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
location.innerHTML = 'Latitude is ' + latitude + '° Longitude is ' + longitude + '°';
$.getJSON(url + "&appid=" + apiKey + "/" + latitude + "," + longitude + "?callback=?", function(data) {
$('#temp').html(data.currently.temperature + '° F');
$('#minutely').html(data.minutely.summary);
});
}
function error() {
location.innerHTML = "Unable to retrieve your location";
}
location.innerHTML = "Locating...";
}
weather();
Thank you for your help!