I’ve been wracking my mind for ages as to why the Weather API is still not working. I am using similar syntax as the geolocation API, and that is rendering just fine. At this stage I’m just trying to ensure I can pull the data in correctly, after which I will start on the styling and frontend.
Thanks
My HTML
<html>
<head>
<meta charset="UTF-8">
<title>Today's Weather</title>
</head>
<body>
<p id="geoLoc"></p>
<p id="currTemp"></p>
</body>
</html>`
And my JS
//geolocation via freecodecamp exercise
$(document).ready(function(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
$("#geoLoc").html("latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude);
});
}
//jquery current weather via openweathermapp
var lat = position.coords.latitude;
var long = position.coords.longitude;
var weatherURL = "http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+long+"&APPID=****MyKEY****";
$.getJSON(weatherURL).done(function(data){
$('#currTemp').html("current temp: " + data.main.temp);
});
});