Geolocation problem

Hello Capmers,

i am working on my “show local weather” page and i m stuck here for three days :sweat: ,i am not able to get geolocation… challenge’s code not working and tried some other code as well to get location but no luck, i am using chrome Version 56.0.2924.87 (64-bit) .

anybody here can help :slight_smile:

thank you.

Hi @codelerner8,

I think it has something to do with chrome no longer supporting/using geolocation. A quick search should give you more info. :thumbsup:
I recently discovered my weather app also doesn’t work in chrome although it’s fine on firefox, so I’ll need to go back and fix mine too. Ahh more headaches lol :slight_smile:

I couldn’t get the navigator.geolocation working with CodPen. It worked in JSfiddle, but not codePen, so I’m pretty sure it has to do with CodePen not allowing it.

I had to use a geolocation API in order to get latitude and longitude to call the weather api.

Browsers remember the settings for a given website.
You might turn off the geolocation services on codepen.
You can check the settings by clicking on the icon just before page address.

I completed this challenge last week and come across the same problem. After a few days of pulling my hair out I learned why. Since version 50 of Chrome, getting the user’s geolocation is blocked unless the site has a secure connection (URL has to be HTTPS not HTTP) and codepen I found is usually not secure. If is is the case, change the http to https and see if it works this time.

If this is the case, you will also have use a different weather api as well I’m afraid because the json object it sends you is through a http URL which Chrome blocks too. I used this api instead and it works really well

Hope this helps

1 Like

Thanks alot yes i did try typing HTTPS and it worked, but i think this is not a solution so will definitely try this API what u have suggested. :slight_smile:

it is working if i type HTTPS otherwise no :frowning:

I think the https solution is the smarter solution. Using the built-in geolocation in the browser is better. The geolocation API gave me a wrong location when I was checking out the app on my phone and LTE. Navigator.geolocation.getLocation() will be more accurate and also a little more simple on the code. Also, you could use the geolocation API as a fallback if they have the location services on their browser turned off…I think.

thank you for so much support but now again m stuck in getting city name through latitude and logitude :frowning: is this the way we can get city name or there is another way to do this? help

I think the better API for weather is this one

you can call it, by city name, coord, etc

I used to get latitude and longitude and city name. I used for the weather info.

yes it seems the best option

What do you guys used for the weather icons??

the openweathermap api has icons. I used them. They’re not very pretty, but they make life easier.

I still didn’t get response from API :frowning: unable to get data