Geolocating in native JavaScript.

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

Omars Codex

Written by

I’m a software developer and sustainability advocate.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade