Created
December 12, 2018 10:35
-
-
Save djmeph/30262c4591f46eeaa7c75d8af8c6493d to your computer and use it in GitHub Desktop.
Draw a circle in google maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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