Trouble with Weather - Dark Sky API and Chrome


#1

Hey everyone, so this is my current Weather Locator Project thing. I cannot seem to get it to work whatsoever, the code is able to use the IP API on my work laptop on Internet Explorer but not on my personal laptop on Chrome for some reason. Then, when I do get IP coordinates, my dark sky api does not run. Could anyone help me with this? I’ve been trying to look through the forum for help but I haven’t been able to solve it.


#2

Codepen requires you to make all of your API calls over HTTPS. Your location API only works over HTTP, so you’ll need a different API that works over HTTPS, like freegeoip.net or ipinfo.io.

If you update your code for another API, the rest of your code works fine:

function getLocation() {
  var urlIP = "https://freegeoip.net/json?callback=?";
  $.getJSON(urlIP, function(data) {
    var LocInfo = data.latitude + "," + data.longitude;
    $("#city").text(data.city + ", " + data.region_code);
    createURLandInfo(LocInfo);
  });
}

Moving forward, you can debug these errors by looking at your browser’s developer console and searching for the errors provided. (Ctrl+Shift+J on Windows / Command + Option + J on Mac). The console in codepen won’t give you the errors you need.


#3

I found this challenge to be particularly challenging since the Dark Sky API blocks Cross Origin Requests, and the Open Weather API won’t work on SSL unless you pay $80+ per month, I put together a quick hack to work around the API issues (See: For those of you who are stuck on the Weather API Projects), realistically I want to write a Heroku app that does this that anyone can deploy without too much work, I’ll try to do that in the near future. The example proxy I provided should work with either of the APIs. Good luck :slight_smile:


#4

Sorry to leave your response hanging for so long, I didn’t have my notifications on for the forum :(. Thank you so much though, this worked perfectly.


#5

You can try the ZetPush https://zetpush.com/ is good tool.