I'm trying to write some code using Javascript/ jQuery/ Google Maps API.
However, the order of execution in my script is a bit weird.
var flats=[];
function initialize() {
var mapOptions = {
zoom: 10,
center: new google.maps.LatLng(50.062, 19.937),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
/* Puling flats data using my API */
$.getJSON("http://ks3353689.kimsufi.com:5000/v1/closest_pointlng=19.937&lat=50.062",parseFlat);
function parseFlats(data){
/* I put flats data in format usable by Google maps API */
$.each(data, function(i, item){
flat = [];
flat.push('flat_name');
flat.push(parseFloat(item.latitude));
flat.push(parseFloat(item.longitude));
// z-index to display flats on map
flat.push(i+1);
flats.push(flat);
});
console.log("I'm inside the function");
}
console.log("activating markers");
setMarkers(map, flats);
}
I thought that jQuery API call will be executed before setMarkers function, but when I look into firebug, the order is different:
activating markers
I'm inside the function
What am I doing wrong? How can I make sure jQuery part is executed before setMarkers function?
setMarkers()at the end of your callback function.