-
-
Save parzibyte/9bd01d0cf1549a645fb5f2de75601ceb to your computer and use it in GitHub Desktop.
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
const calcularDistanciaEntreDosCoordenadas = (lat1, lon1, lat2, lon2) => { | |
// Convertir todas las coordenadas a radianes | |
lat1 = gradosARadianes(lat1); | |
lon1 = gradosARadianes(lon1); | |
lat2 = gradosARadianes(lat2); | |
lon2 = gradosARadianes(lon2); | |
// Aplicar fórmula | |
const RADIO_TIERRA_EN_KILOMETROS = 6371; | |
let diferenciaEntreLongitudes = (lon2 - lon1); | |
let diferenciaEntreLatitudes = (lat2 - lat1); | |
let a = Math.pow(Math.sin(diferenciaEntreLatitudes / 2.0), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(diferenciaEntreLongitudes / 2.0), 2); | |
let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | |
return RADIO_TIERRA_EN_KILOMETROS * c; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment