Geolocatiation is not working

Geolocatiation is not working
0

#1

This is my project code http://codepen.io/sergiosalfer/pen/grQZkV

I’ve tried so many ways to see the latitude, but it’s not working, I’ve seen other pen code and It’s working (https://codepen.io/leemark/pen/ezhlD).

I copied the code in the geolocatitation challenge and it isn’t still working.

I don’t know what to do.


#2

I don’t know the exact explanation - but it’s a scope issue that probably has to do with how js is writing - i rewrite your code like this

 navigator.geolocation.getCurrentPosition(function(position) {
    var latitude = position.coords.latitude;
     var longitude = position.coords.longitude;
     $("#latitude").html(latitude);  
  });

and it did work properly - i also reset it to what you had previously

Scope is tricky business - it might be a document.ready issue


#3

I’ve been banging my head on the wall for this for a day now… having the exact same issues as you. Code from other geolocation examples seems to work but when I run it in my own pen it gets error code 1. I’m using chrome, not sure if that’s an issue.


#4

Now, I’m using this to get the locatitation http://ip-api.com/json/?callback=?"


#5

Yep I just found that and was coming back to post here. Thanks and good luck!


#6

Your current code has a typo due to the case sensitive nature of javascript.

Instead of $.getJson, use $.getJSON. That should help you make the request.


#7

Thans all, my code is now working in my lnotebook, but not in codepen.


#8

@sergiosalfer and @NickWright, as I mentioned here: http://forum.freecodecamp.com/t/google-geolocation-down/23174/5?u=cpcode , the problem is to do with Google depreciating navigator.geolocation if the page is accessed from http, as opposed to https.

The work around is to manually put https:// in front of codepen.io, and then give that link to others looking at your page. I may also put up an alert message to that effect.

Thanks for the ip-api.com link, though it isn’t as accurate.

I also found this link on the same issue: