Show local weather - open weather API wont run in codepen

You need to put your AJAX call inside your callback function to the geolocation.

Otherwise when the AJAX is called, lat and lon are not defined yet.

There are some pretty good explanations of asynchronous behavior in this thread.

2 Likes