Geolocating in native JavaScript.
Jul 27, 2017 · 1 min read
Did you know? There’s an easy built-in way to get the current location of the browser you’re currently using. It’s ‘easy’ because it doesn’t use a third-party library or anything — but it comes at a cost as I’m finding.
The general idea is this:
var myCoordinates;navigator.geolocation.getCurrentPosition(function(position){ return myCoordinates = position.coords })
Which allows you to do:
let latitude = myCoordinates.latitude;
let long = myCoordinates.longitude;This works in the Chrome console after a slight delay. It doesn’t work in Safari due to `localhost` being “insecure” (haha). The hardest part, though, is in using it on the server…
TO BE CONTINUED.
