I am unable to get a response from getJSON from OpenWeatherMap for the weather app project.
The strange thing is that the actual API call to OpenWeatherMap does return a valid JSON object.
So, I wanted to output a debug string to the console to confirm getJSON is running but nothing outputs there as well.
What am I missing?
var apiCall = "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&units=imperial&APPID=" + myAPIKey;
console.log(apiCall);
// I've taken this api call and pasted it into a webpage and it returns a valid JSON object
$.getJSON(apiCall, function(json){
console.log("test");
// Wanted to output a debug string to the console. But "test" never outputs to the console.
});
Your immediate issue is a cross domain issue. ie, geo location requires https in some (and soon all) browsers. But because your api is http, it hangs as a security issue.
The solution is to ditch geo (not an option for me, personally, cos it’s cool) or use a different API. dark skies and Apixu amongst others support this feature for free. Open-weather makes you pay to use https.
you can also use crossorigin.me for a quicker fix but imo the performance hit makes it untenable.
In short, choose a different api service if you want to use geo.
Thanks mark. That was indeed the problem. Will try out both the crossorign.me solution as well as using a different weather api service (which is odd since OpenWeatherMap was the api service that the FreeCodeCamp project guide recommended).