Skip to content

Instantly share code, notes, and snippets.

@djmeph
Created December 12, 2018 10:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djmeph/30262c4591f46eeaa7c75d8af8c6493d to your computer and use it in GitHub Desktop.
Save djmeph/30262c4591f46eeaa7c75d8af8c6493d to your computer and use it in GitHub Desktop.
Draw a circle in google maps
module.exports = (coord, brng, dist) => {
dist = dist / 3958;
brng = brng.toRad();
var lat1 = coord[1].toRad(), lon1 = coord[0].toRad();
var lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist) + Math.cos(lat1) * Math.sin(dist) * Math.cos(brng));
var lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));
if (isNaN(lat2) || isNaN(lon2)) return null;
return [lon2.toDeg(), lat2.toDeg()];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment