Navigator.geolocation problem

Hey. So i’m trying to do the local weather project and want to get my location coordinates. since there already was a task on freecodecamp called “Get Geolocation Data” in witch you need to get your own location, i used the same code

<div id = "data">
  <h4>You are here:</h4>

  if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    $("#data").html("latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude);

and pasted it into the codepen, but it does not load my location coordinates. and i cant understand why. (i allowed browser to get my location, im added JQuerry on my pen)

Hello naglis,

I cant see any error in your code and its working perfectly fine on my browser. (Google chrome)

Hi. well, thats the thing. cause the same code works in Get Geolocation Data task, but doesn’t in codepen.

here’s my pen link

when i log into my pen google chrome doesnt even ask me can it access my location. same thing with explorer.

This how your Pen looks in my browser.

Please try this link and recheck weather geolocation is enabled for your browser.

1 Like

Yep, that fixed the problem. Thank you so much!

1 Like