Hello campers,
I am trying to get geo location by using the following piece of code from a FCC challenge called ‘Get Geolocation Data’
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
$("#data").html("latitude: " + position.coords.latitude + "
longitude: " + position.coords.longitude);
});
}
For some reason this does’t work within my pen. Could anyone take a look for me please?
The geolocation feature only works over HTTPS (except on localhost), so you need to make sure you go to https://codepen.io/Chelsea-Li/pen/MpKPzq instead of http://codepen.io/Chelsea-Li/pen/MpKPzq
After that you’ll need to make sure your weather API call is an HTTPS URL too.
Thanks for your reply.
I clicked on both link you gave me, none of them works for me. Does it work for you?
I have to say, I’m puzzled why geolocation isn’t working. Maybe someone will come along and point out what’s probably a small thing, but I’m still trying to see what’s wrong.
It works on Firefox, but not on chrome for some reason apparently
Yeah, it looks like a Chrome thing. I forked your pen and added an error handler to getCurrentPosition
and I see it’s spitting out an error, "Network location provider at 'https://www.googleapis.com/' : Returned error code 403."
Error 403 is Forbidden, so I’m curious what’s going on.
A reddit thread a year ago makes it sound like this at least isn’t a problem with your code.