Reputation: 517
I try and run this code in my react app on local host on firefox V74.0 edit: there are two functions callbacks, also i expanded my entire code, as opposed to the just navigator line of code.
function callback(position){
comment.pos = {
lat: position.coords.latitude,
long: position.coords.longitude,
}
DB.postNewThread(comment);
}
navigator.geolocation.getCurrentPosition(callback,function(error){
if(error){
// actually this function is only ever called if there is an error i think
// i settle for a small approximation with this particular API called api.ipstack.com
fetch(geouri)
.then(resp=>resp.json())
.then(l=>{
const obj = {
coords: l
}
callback(obj)
})
.catch(function(e)
console.log(e);
alert("You can not be using HTTPS if your browser doesnt support native geo locator. Update Firefox or Chrome")
});
console.log(error);
}
});
the callback function is never executed even when i put it in the in console. the dialoge pops up and i click allow location.Navigator.geolocation is a truthy object.
Upvotes: 0
Views: 249
Reputation: 221
Maybe you are running into an error ?
navigator.geolocation.getCurrentPosition(success[, error[, [options]])
You can add another callback function for errors.
navigator.geolocation.getCurrentPosition(function(position){
console.log("GOT THE POS",position);
}, function(error) {
console.log(error)
});
Upvotes: 1