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
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.
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.