Problem getting geolocation information in local weather

Problem getting geolocation information in local weather
0

#1

Hello fellow campers,

I am developing the code for showing the local weather. The code, I am writing is working neither in my codepen account or from my local browser. I think, for me the “geolocation” is not working. However, I think it’s not the problem of the browser as I tried similar codes from w3schools, freeCodeCamp exercise under “JSON API and AJAX” and some other sites. Everywhere their code is working from my browser. I even pasted similar code in my codepen but still not working. Executing code from other sites (including free code camp),
if (navigator.geolocation)
for the above line the browser asks for permission however my codepen application doesn’t ask anything. Here is my codepen link,


Can anyone please help me figure out what I am missing ? Do I need to add any other library ? Your help is much appreciated.


#2

You made a function for getting location, but you forgot to call it.


#3

Also, you need to add an element such as a div to the html. Your code refers to an element with id=“demo” so you could add this below the h1 tags.

 <div id="demo"></div>

#4

Hello Kevcomedia… Thanks much for your prompt reply . It really helped !!! I changed my code and now it’s working fine in my codepen. However, the same code is not running from my local system browser (chrome). Do you have any idea what prompts that ? Do I need to include any library for local system ?


#5

Hallo randelldawson…

Thank you for your reply. I was trying different solutions as my own was not working and hence did this silly mistakes. Thanks much for helping me figuring this. I was literally pulling my hair …


#6

geolocation requires the page to be served using https from a webserver - it won’t work if the page is accessed from the local filesystem