Obecnie pracuję z geokodowanie google maps' i trzeba utworzyć tablicę, która będzie zawierać tablice jako elementy.
Zasadniczo trzeba utworzyć w ten sposób:
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
Ale dynamicznie! Muszę tę tablicę umieścić szpilki na mapie później.
Co ja robię:
var locations = []; // The initial array
for (var i = 0; i < addresses.length; ++i){
var address=addresses[i]; // the address e.g. 15 Main St, Hyannis, MA
geocoder.geocode({ 'address': address}, function(results){
var obj = {
0: address,
1: results[0].geometry.location.hb,
2: results[0].geometry.location.ib,
3: i
};
console.log(obj);
locations.push(new Array());
locations[i].push(obj);
});
};
console.log(locations.length);
Problem, pytanie:
Nie widzę żadnych błędów, ale w miejscach końcowych [] tablica jest pusta.
Oto ekran konsoli w razie potrzeby:














