Looking for tips on the weather API page!

Hey guys! I have been trying to get this weather API to work for a while now, but it seems that I am stuck.

The problem I’m facing is basicly getting hold of the API data. I’ve found my current position, but I am having problems returning the coordinates, or the URL containing the coords so I can use it in the getJSON method.

I would really appreciate if anyone took their time to have a look at my code. Link to the pencode - https://codepen.io/JarandNikolai/pen/MbazVp

Also: I am new at free code camp, and really excited to be here! :slight_smile:

  • Jarand

The reason your code doesn’t work as expected is that the navigator.geolocation.getCurrentPosition is asynchronous since it takes callback for success and error. One solution is to move the
$.getJSON(url, function(json){
$(“body”).html(JSON.stringify(json));
});

code into your success function

Thank you very much! :smiley: