Skip to content

Instantly share code, notes, and snippets.

@xemasiv
Last active May 13, 2018 01:51
Show Gist options
  • Save xemasiv/c698d51bf0d6819e53af62aa80213fd4 to your computer and use it in GitHub Desktop.
Save xemasiv/c698d51bf0d6819e53af62aa80213fd4 to your computer and use it in GitHub Desktop.
Geolocation distance as a factor

Blind / Passive Approach

var x = cheapRuler(lat1, 'kilometers');
x.distance([lat1, long1], [lat2, long2]);

Proactive Approach

var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};
function success(pos) {
  var crd = pos.coords;
  console.log('Your current position is:');
  console.log(`Latitude : ${crd.latitude}`);
  console.log(`Longitude: ${crd.longitude}`);
  console.log(`More or less ${crd.accuracy} meters.`);
}
function error(err) {
  console.warn(`ERROR(${err.code}): ${err.message}`);
}
navigator.geolocation.getCurrentPosition(success, error, options);
OpenLocationCode.encode(lat, long)
OpenLocationCode.decode(lat, long)

WebSockets

Visualization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment