Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
How to access data objects inside an array of array in javascript/react for Google Maps lat/lng?

How do I map over this data in javascript? I am trying to loop over this data for Markers in google maps. Having trouble grabbing the lat and lng.

Data from the console.log array --> array --> object --> lat/lng

LatLng: [
        [
            {
                "lat": 28.0440005,
                "lng": -82.3992308
            },
            {
                "lat": 28.050104,
                "lng": -82.39597859999999
            },
            {
                "lat": 29.6900252,
                "lng": -82.3733803
            },
            {
                "lat": 29.6900252,
                "lng": -82.3733803
            },
            {
                "lat": 29.6900252,
                "lng": -82.3733803
            },
            {
                "lat": 29.6900252,
                "lng": -82.3733803
            }
        ]
    ]

This is my javascript code for Google Maps. Tried grabbing the lat/lng this way for the marker to loop through the data. Not sure of other methods to include. LatLng is an object of the array, so I could not use a map method at the beginning.

    {Object.values(LatLng).map(({ lat, lng }, index) => (
            <Marker lat={lat} lng={lng} key={index}>
              {console.log(Object.values(LatLng))}
            </Marker>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The LatLng array you shared is a 2-d array of objects.

You need to do loop over the first element in that array. Tree-shake and extract the LatLng array first.

const {LatLng} = // Insert your object structure here

 {LatLng[0].map(({ lat, lng }, index) => (
            <Marker lat={lat} lng={lng} key={index}>
              {console.log(Object.values(LatLng))}
            </Marker>)))}
about 4 years ago · Juan Pablo Isaza Denunciar

0

{  
  LatLang && latLang[0].map((item, index) => (
  <Marker lat={item[lat]} lng={item[lng]}                key={index}> 
   {console.log(item[lat] , item[lng])}
  </Marker>
)}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try:

{Array.isArray(data[0]) && data[0].map((element, index) => (
    <Marker lat={element.lat} lng={element.lng} key={index}>
        {console.log(element.lat, element.lng)}
    </Marker>
))}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda