Navigator.geolocation problem

Navigator.geolocation problem
0.0 0

#1

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

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

----------------------js
$(document).ready(function(){
  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)


#2

Hello naglis,

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


#3

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 https://codepen.io/Naglis/pen/KQmEjb

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


#4

This how your Pen looks in my browser.

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


#5

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