Weather App location help

Weather App location help



I’m starting out the local weather App, but the location doesn’t seem to update from the ajax request. Anyone have any ideas what is missing from my code?



You can’t make requests to insecure (http) addresses from secure locations (codepen is served via https).


hmm even when I change it to (https) the location doesn’t seem to update. Do you think it could be my browser?


Are you sure the resource you are calling supports https?


I think that was the problem, thanks!


Now my last problem is trying to display the image, any ideas on my code?


I think you should use navigator.geolocation.getCurrentPosition() to get the user’s coordinates instead of what you’re using. I looked at the object that the weather API is returning and the icon is missing. That’s why it’s not showing up. Then I looked at the coordinates and they’re different compared to what I get from navigator.geolocation.getCurrentPosition(). That may be why the weather API is not working properly. The icon showed up in your Pen after I replaced what you used to get the coordinates with navigator.geolocation.getCurrentPosition().


hmmm I am using the navigator.geolocation.getCurrentPosition() now but the icon still does not appear for me. Also my divs for #condition and #description appear to be defaulting to “clouds” and “broken clouds” but I am not sure where it is getting that information.


I cut and pasted the contents of the function getWeather() into the the end of the foundLocation(position) function and it worked. This may be because the location gets found AFTER you make the ajax call, and that’s why you’re getting problems. By doing the AJAX call inside the foundLocation() function, you ensure that you’re making the call after you get the right coordinates.