Reputation: 606
I am building an google map on my web page. This map has some markers. These markers are created with information of a json file. This all works fine. But when I want to use a list of all markers, this list.length is always 0 in an other function. Only in the function where i put the markers into the list, the list isn't empty.
I made a fidler of my code, so it's more viewable for you guys.
The problem is with the array "positions" and the function buttons. The alert in the buttons function, shows 0. And I have no idea why..
Thanks in advance!
Here my Fiddle
Upvotes: 1
Views: 165
Reputation: 48793
The idea is simple. You are calling Ajax
asyncronously. When you are trying to alert positions.length
value, your Ajax
is not being delivered yet,and your position
array is not populated with values and is empty(.length=0
). Put buttons()
call inside of the callback:
loadMarkers();
//buttons();
// | //.............
// | //.............
// | //.............
polyline.setMap(map);
// --->
buttons();
});
Upvotes: 1