I can't pull the latitude or longitude out of the browsers API and have been trying for probably two weeks. Have been reading everything I can find and taking a class on functions, but this is just over my head. Is there a way I can save it to a variable so I plug it into another function. Have tried a couple ways
Way 1:
const x = navigator.geolocation.getCurrentPosition(({coords})) => {
return pos.coords.latitude
}
Way 2:
navigator.geolocation.getCurrentPosition(function (position) {
if ((splitCoords[1] - position.coords.latitude >= -0.009 && splitCoords[1] - position.coords.latitude <= 0.009) &&
(splitCoords[0] - position.coords.longitude >= -0.009 && splitCoords[0] - position.coords.longitude <= 0.009))
{
return "Yes"
} else {
return "No"
}
})
What's throwing me off is the fact that getCurrentPosition() is, itself, a function.. and I can't find anywhere that shows me how to query certain coordinates out of it. I console.logged the whole thing in the browser and went down the tree and 'coordinates' don't exist. Am I on the right track?
I was able to find the answer in a series of youtube videos starting with this one. The videos are awesome, highly recommend for anyone who stumbles across this looking for a solution.