Help needed with weather app

The first call is working, I get the lat and lon but when I run the 2nd call, console still says “assigning the data…” Its not doing anything. Any ideas? I have gone over it multiple times and its just not doing anything, not sure if I made too many calls or I am missing something. Any help would be greatly appreciated!

var API_KEY = ‘xxx’;
$(function() {

var loc;
$.getJSON(‘http://ipinfo.io’, function(d){
console.log(“assigning the data…”)
loc = d.loc.split(",");
console.log(loc);
$.getJSON(‘http://api.openweathermap.org/data/2.5/weather?lat=’ + loc[0] + ‘&lon’ + loc[1] +’&APPID=’ + API_KEY, function(wd){

console.log("got the data ,", wd);
 })

})
})

I would guess it’s because you have the API key set to “xxx”. (Hint: if you’re trying to use Vin Diesel’s API key, it’s “xXx”.) When I extract that second url and pump it into the address bar of the browser, I get the following return object:

// 20170426090743
// http://api.openweathermap.org/data/2.5/weather?lat=37.8309&lon-122.2196&APPID=xxx

{
  "cod": 401,
  "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."
}

You need a valid key.

I have a valid key, i didn’t want to publish it

OK, fair enough. I’m not sure ISIS is looking for your weather map API key so they can hack into NORAD, but I’ll play along. :wink:

If I plug my API key into your code and add these console statements into it:

var API_KEY = "xXx";
$(function() {
  var loc;
  $.getJSON("http://ipinfo.io", function(d) {
    console.log("assigning the data...");
    loc = d.loc.split(",");
    console.log(loc);
    var url2 = "http://api.openweathermap.org/data/2.5/weather?lat=" +
        loc[0] +
        "&lon" +
        loc[1] +
        "&APPID=" +
        API_KEY;
    console.log(url2)
    $.getJSON(
      url2,
      function(wd) {
        console.log("got the data ,", wd);
      }
    );
  });
});

I pull that string out of the console and plug it into the address bar of a browser. This should be the first thing you do when you have a problem like this. (Although you can also get it more directly if you know how to navigate the dev tools, but this works and is educational.) I got this in response:

// 20170426100304
// http://api.openweathermap.org/data/2.5/weather?lat=37.8309&lon-122.2196&APPID=xXx

{
  "cod": "400",
  "message": "Nothing to geocode"
}

Upon close examination of that API string, I see that you are missing an “=” after the lon making it an invalid string. Adjust your code and you should be good to go:

$.getJSON('http://api.openweathermap.org/data/2.5/weather?lat=' + loc[0] + '&lon=' + loc[1] +'&APPID=' + API_KEY, function(wd){

@ksjazzguitar thank you kevin, its working.