Created
October 9, 2019 09:16
-
-
Save michaeljymsgutierrez/fd6a1b5d29e7f0c43e7faf09a83bead8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Set of functions for calculating distance | |
| */ | |
| const getDistance = (lat1, lon1, lat2, lon2) => { | |
| let R = 6371; | |
| let dLat = deg2rad(lat2 - lat1); | |
| let dLon = deg2rad(lon2 - lon1); | |
| let a = | |
| Math.sin(dLat / 2) * Math.sin(dLat / 2) + | |
| Math.cos(deg2rad(lat1)) * | |
| Math.cos(deg2rad(lat2)) * | |
| Math.sin(dLon / 2) * | |
| Math.sin(dLon / 2); | |
| let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | |
| let d = R * c; | |
| return d; | |
| }; | |
| const deg2rad = deg => { | |
| return deg * (Math.PI / 180); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment