I have some Google Maps JS that plots a number of markers on a map. However, when loading the markers I noticed that the images were not loading in time and so the markers were not being placed. To get around this I modified my function that returned a map marker as follows:
function newGoogleMapPin(type){
var imgpath = "img/gmapicons/"+type+".png";
var img = new Image();
img.src = imgpath;
var imgloaded = false;
while(imgloaded == false) {
img.onload = function() {
imgloaded = true;
}
}
return new google.maps.MarkerImage(imgpath, new google.maps.Size(img.width, img.height));
}
Problem being is imgloaded
is never set to true
,
Am I misunderstanding closures? (I guess so!)