Hey guys. I need help working with APIs in code pen. it doesnt seem to get the API call. it doesnt even work with the geolocation challenge
Do you have a link?
Also, most likely there will be an error message in your browser console with more information.
the error message says “Type error, $.getJson is not a function”
$.getJson
should be
$.getJSON
if it’s any consolation, it worked on my end, but I’m running MSedge and had to disable just about every single security feature in my browser just to be able work in CodePen -.-
Fixed my problem. Thanks a lot
is there anything wrong with this string concatenation?
var apiCall = "http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+long+"&appid=4c78e3460c3ae1baf6c9b67990be0803";
here’s how I broke the call down, note that I had to set the var OWM_API_KEY global (outside) and disable every security function in my MSedge browser for it to get me data.
$.getJSON('http://api.openweathermap.org/data/2.5/weather?lat=' + uLat + '&lon=' + uLon + '&appid=' + OWM_API_KEY + '&units=imperial'
the problem is that im actually getting data with hard coded longitude and latitude values. The minute i concatenate the variables, it stops working especially the longitude value.
when I run it my side it looks like the weather api is running BEFORE the GeoIP lat/long is returned. So the weather API is running with this error:
http://api.openweathermap.org/data/2.5/weather?lat=undefined&lon=undefined&appid=4c78e3460c3ae1baf6c9b67990be0803&units=imperial
> {“cod”:“502”,“message”:“Error: Not found city”}
notice the "undefined" lat/lon values …
I was starting to suspect that. What do you think i can do about it?
try this series from CodewithNick, it helped me a LOT:
Ill definitely do that. Thanks a lot