Weather API concatenating coordinates

Weather API concatenating coordinates


I’m working through this and I’ve found a way to get my device’s location with the IP address. What I’m not too sure of is how I’m supposed to take that response and then concatenate it into the request URL for the weather data. I keep getting an error that my variables in line 10 and 11 are not defined on line 19.

It seems like it’s just a scope issue that I just need more practice with. I’ve tried rearranging the functions, but currently I’m stumped.


You need to move your call to the getWeather function to be inside the .get anonymous callback function (below):

$.get("", function (response) {
    loc = response.loc;
    latlon = loc.split(',');
    lat = latlon[0];
    lon = latlon[1]; 

You had it outside of the call to the API and since the get function is asynchronous, the getWeather function was being called before the response was back from the API, so you were getting undefined for the lat and lon values.


I knew it was something embarrassingly simple. Thanks :sweat_smile: