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

192
Visualizações
Google Maps loadGeoJSON getGeometry.get() latlng disappear

Working through this tutorial from Google: https://developers.google.com/codelabs/maps-platform/google-maps-simple-store-locator

Github code here: https://github.com/googlecodelabs/google-maps-simple-store-locator

file: app.js functions: initMap(), calculateDistances();

My specific issue is that the latlng properties get lost somewhere. The map loads and all the map points load. However when I use the search/autocomplete the map.data is passed as parameter through this function (line 218)

const rankedStores = await calculateDistances(map.data, originLocation);

and is parsed with this function (line 234)

async function calculateDistances(data, origin) {
   const stores = [];
   const destinations = []
  // Build parallel arrays for the store IDs and destinations
  data.forEach((store) => {
     const storeNum = store.getProperty('storeid');
     const storeLoc = store.getGeometry().get();
     console.log(storeLoc);
     stores.push(storeNum);
     destinations.push(storeLoc);
});

in the console.log no geometries appear. the objects and respective latlng properties are there just not the actual coordinates. when I view the storeNum in console. they display as they should. I have verified the coordinates exist in jSON and they map points prove that the map.data.loadGeoJSON is working correctly. I am just going crazy trying to find where the coordinates went and how to ensure they get passed to the calculateDistances function. Any help is appreciated.

Screenshot A: screenshot A console.log(store.storeLoc)

Screenshot B:

screenshot B console.log(store.toUrlValue(6))

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

0

To retrieve the coordinates from a google.maps.LatLng object (which is what is returned by store.getGeometry().get()), use the .lat() function for latitude, the .lng() function for longitude, or the .toUrlValue() function for a comma separated string containing both.

async function calculateDistances(data, origin) {
   const stores = [];
   const destinations = []
  // Build parallel arrays for the store IDs and destinations
  data.forEach((store) => {
     const storeNum = store.getProperty('storeid');
     const storeLoc = store.getGeometry().get();
     console.log(storeLoc.toUrlValue(6));
     stores.push(storeNum);
     destinations.push(storeLoc);
});
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