Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
Obtengo los datos json del archivo externo y puedo consolarlos. pero no puedo colocar los valores en un mapa de Google

La primera img es el código javascript. Llenar la matriz y luego intentar cargarla en un mapa a través de un bucle for https://i.stack.imgur.com/0L0a3.png

esta es la salida de registro de la consola de la matriz... https://i.stack.imgur.com/Ghsw5.png

los marcadores no se colocan en la longitud y latitud especificadas.

el error dado es: no se pueden leer las propiedades de undefined (leyendo 'latitud')

 var array=[]; $.getJSON('station.json', function (json) { for (var key in json) { if (json.hasOwnProperty(key)) { var item = json[key]; array.push({ place: item.place, latitude: item.latitude, longitude: item.longitude, }); } } }); for (var i = 0; i < array.length; i++) { marker[i] = new L.marker([array[i][2]['latitude'], array[i][2]]['longitude']) .bindPopup(array[i]['place']) .addTo(mymap); } console.log(array) [1]: https://i.stack.imgur.com/d428i.png [2]: https://i.stack.imgur.com/Syej2.png
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El problema es que $.getJSON es una función asíncrona que necesita usar como una promesa o manejar el mapa en la función de devolución de llamada

solución 1

 var arrayPromise= $.getJSON('station.json').then (json => Object.values(json).map(item => ({ place: item.place, latitude: item.latitude, longitude: item.longitude, }) ) arrayPromise.then(arr => arr.forEach(({place, latitude, longitude}) => { marker[i] = new L.marker(latitude, longitude) .bindPopup(place) .addTo(mymap); }) )

solución 2

 $.getJSON('station.json', function (json) { Object.values(json).forEach((item, i) => { marker[i] = new L.marker([item.latitude, item.longitude]) .bindPopup(item.place) .addTo(mymap); }) })
about 4 years ago · Juan Pablo Isaza Report

0

Intente usar '''Array.foreach''' o '''Array.map''' en lugar de un ciclo for, veamos el resultado

 Array.foreach((item,index)=>{ marker[i]= new L.marker([item.place, item.latitude,item.longitude])});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!