Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Convert distance between 2 points in a plane into distance between two point on Earth

So finding the distance between two points in a plane and between two points on Earth is a pretty easy google search away, but converting one to the other I couldn't find how to do.

Using these two functions

function dist = (lat1: number, lng1: number, lat2: number, lng2: number) => {
    return Math.sqrt((lat1 - lat2) * (lat1 - lat2) + (lng1 - lng2) * (lng1 - lng2))
}

function distOnEarthInMeters = (lat1: number, lng1: number, lat2: number, lng2: number) => {
    if (lat1 === lat2 && lng1 === lng2) return 0

    const radianLat1 = lat1 * (Math.PI / 180)
    const radianLng1 = lng1 * (Math.PI / 180)
    const radianLat2 = lat2 * (Math.PI / 180)
    const radianLng2 = lng2 * (Math.PI / 180)
    const earthRadius = 6378137
    const diffLat = radianLat1 - radianLat2
    const diffLng = radianLng1 - radianLng2
    const sinLat = Math.sin(diffLat / 2)
    const sinLng = Math.sin(diffLng / 2)
    const a = Math.pow(sinLat, 2.0) + Math.cos(radianLat1) * Math.cos(radianLat2) * Math.pow(sinLng, 2.0)
    return Math.floor(earthRadius * 2 * Math.asin(Math.min(1, Math.sqrt(a))))
}

I get these:

dist(-27, -42, -26, -41) === 1.4142135623730951
distOnEarthInMeters(-27, -42, -26, -41) === 149386

But can can I turn one into the other without knowing the coordinates?

make 1.4142135623730951 become 149386 and 1.4142135623730951 become 149386

(copied to https://math.stackexchange.com/questions/4489148)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As others said this is a math problem. But the answer is no you can't find it. Every map projection changes some distances on the globe. Some projections can conserve some distances, but never all.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda