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

221
Visualizações
error when accessing latitude and longitude value in geolib

In my react native app I have used geolib to find the nearest place to a certain point from a list of places, like this

const nearestPlace = geolib.findNearest({ latitude:6.4423456, longitude:75.9095818 }, (places));

once I console log nearestPlace I get one latitude, longitude pair but when I try to get the value of the latitude like this,

const latitudeValue = nearestPlace.latitude

It's giving me an error saying property latitude does not exist on type 'GeolibInputCoordinates' so I can't get the latitude value.

Any Idea how to solve this?

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

0

I'd suggest you use the getLatitude, getLongitude functions. This will give you values for the latitude and longitude.

Perhaps your places array is in a different format such as { lat, lon } and this is what is causing the issue. They may not necessarily have a latitude or longitude property.

const places = [{ lat: 6.45, lon: 75.90 }, { lat: 6.44, lon: 75.91 }];
let nearestPlace = geolib.findNearest({ latitude: 6.4423456, longitude: 75.9095818 }, (places));
console.log('Nearest place:', nearestPlace);

const latitudeValue = geolib.getLatitude(nearestPlace);
const longitudeValue = geolib.getLongitude(nearestPlace);

console.log('Latitude:', latitudeValue);
console.log('Longitude:', longitudeValue);

// You can also 'normalize' this like so: 

const point = { latitude: latitudeValue, longitude: longitudeValue};
console.log('Nearest point (normalized):', point);
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://unpkg.com/geolib@3.3.1/lib/index.js"></script> 

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