Problem getting geolocation information in local weather

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.

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

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>

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 ?

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 …

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