Weather App location help

Weather App location help
0

#1

Hi,

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?

Thanks


#2

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


#3

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


#4

Are you sure the resource you are calling supports https?


#5

I think that was the problem, thanks!


#6

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


#7

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().


#8

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.


#9

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.