I'm doing the "local weather" front-end development challenge on freecodecamp.com, and I'm having some trouble making an API call to some weather APIs. The challenge revolves around getting the user's location, and then making a call to a weather API to display the weather in their area. I have tried to use Dark Sky API and OpenWeatherMap API, but neither of them return anything. I can put both API links into my browser, and they both display the information I need, but when I put them into my javascript, they fail to return the information. Here is my current attempt with $.ajax and the Dark Sky API:
$(document).ready(function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
//$("#loc").html(lat + " " + long);
$.ajax({
url: "https://api.darksky.net/forecast/96dd30a49debe62a67b208f705e3d706/" + lat + "," + long,
success: function(json) {
$("#loc").html("Your location: " + json.latitude + "," + json.longitude);
$("#temp").html("Temperature: " + json.currently.temperature);
$("#fc").html("Test " + json.minutely.summary);
},
error: function(xhr, status, error) {
console.log("error", status, xhr, error);
}
});
});
}
});
Thanks in advance!