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.pngEl 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); }) })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])});