Hi i have pretty large script so i wont post it all here, but i really need help, do not know what to do more …
I have ~300 markers in the maps and they all are loading at the same time, and google can not handle or my script can not handle but i am getting “Address could not be found” in half of them even maybe for more (others loads correctly). But if i delete all apart that one everything works as should !
What to do ? Is there a way to load them few at the time step by step, or is there many markers handler or etc ? (not markersManager, i need them all to be seen in all zoom levels)
Tryed with timeout did not helped !
Some of the code :
function initHeadAddress(searchString) {
if(searchString == 'undefined') {
map.clearOverlays();
var t = setTimeout("showAddress('Himmelev Bygade 78 B, 4000 Roskilde, Denmark',1,'3T Bygningsentreprise A/S','4000','Roskilde','46328328','null','www.3t.dk',null,null)",1000);
var t = setTimeout("showAddress('Nørre Allé 51, 7760 Hurup, Denmark',4,'Idealcombi','7760','Hurup','96882500','null','http://www.idealcombi.dk/',null,null)",1000);
..... A LOT OF THESE HERE MORE !!!!
// default one
showAddress('Denmark', 0, null, null,null,null,null,null,null,searchString);
} else {
// if used search function
showAddress(searchString, 0, null, null,null,null,null,null,null,searchString);
}
}
ShowAddress function:
function showAddress(address, markerType, companyname,postnr, by, phone, fax, web, email, searchString) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
//alert("Adresse " +address+ " blev ikke fundet");
console.log("Adresse " +address+ " blev ikke fundet");
} else {
var myIcon = new GIcon(G_DEFAULT_ICON);
myIcon.shadow = null;
myIcon.infoWindowAnchor = new GPoint(9, 2)
if (markerType == '0') {
myIcon.image = '/files/billeder/../Templates/Designs/Ideal2011/images/Map/googleempty.png';
myIcon.iconSize = new GSize(18, 18);
}
if (markerType == '1') {
myIcon.image = '/files/billeder/../Templates/Designs/Ideal2011/images/Map/googlered.png';
myIcon.iconSize = new GSize(18, 18);
$('#dotRedCheckbox').click(
function(){
if(!$(this).hasClass('activeMarker')){
marker.hide();
} else {
marker.show();
}
}
);
}
else if (markerType == '2') {
myIcon.image = '/files/billeder/../Templates/Designs/Ideal2011/images/Map/googlelblue.png';
myIcon.iconSize = new GSize(18, 18);
$('#dotlBlueCheckbox').click(
function(){
if(!$(this).hasClass('activeMarker')){
marker.hide();
} else {
marker.show();
}
}
);
}
else if (markerType == '3') {
myIcon.image = '/files/billeder/../Templates/Designs/Ideal2011/images/Map/googledblue.png';
myIcon.iconSize = new GSize(18 , 18);
$('#dotdBlueCheckbox').click(
function(){
if(!$(this).hasClass('activeMarker')){
marker.hide();
} else {
marker.show();
}
}
);
}
else if (markerType == '4') {
myIcon.image = '/files/billeder/../Templates/Designs/Ideal2011/images/Map/googlegreen.png';
myIcon.iconSize = new GSize(18, 18);
$('#dotGreenCheckbox').click(
function(){
if(!$(this).hasClass('activeMarker')){
marker.hide();
} else {
marker.show();
}
}
);
}
var markerOptions = { icon: myIcon };
var marker = new GMarker(point, markerOptions);
marker.getPoint();
if(markerType != 0){
points.push(point);
markers.push(marker);
}
if (markerType == 0) {
if(searchString == 'undefined'){
map.setCenter(point, 6);
} else {
map.setCenter(point, 13);
LatD = point.lat().toFixed(5);
LngD = point.lng().toFixed(5);
find_closest_marker(LatD, LngD);
find_closest_marker2(LatD, LngD);
find_closest_marker3(LatD, LngD);
}
}
Lat = point.lat().toFixed(5);
Lng = point.lng().toFixed(5);
var image = '<img src="http://cbk0.google.com/cbk?output=thumbnail&w=85&h=70&ll='+Lat+','+Lng+'" />'; // alt="'+address+'"
map.addOverlay(marker);
if(markerType != 0) {
if(fax != "" && fax != null && fax != 'null'){
var newfax = "Mob.: "+fax+"<br/>";
} else {
var newfax = "";
};
if(web != "" && web != null && web != 'null'){
var newweb = "<a href='"+web+"'>"+web+"</a><br/>";
} else {
var newweb = "";
};
if(postnr != "" && postnr != null && postnr != 'null'){
var newpostnr = postnr;
} else {
var newpostnr = "";
};
if(phone != "" && phone != null && phone != 'null'){
var newphone = phone;
} else {
var newphone = "";
};
//address = address.replace("Denmark, ","");
//address = address.replace(", Denmark","");
//address = address.replace(", 2650 Hvidovre","");
//address = address.replace(", Hurup","");
//address = address.replace("UK, ","");
address2 = address.split(',');
address = address2[0];
var infoboxInfo = '<div class="infoboxall"><div class="infoboxinfo"><div class="infoboxAddress">'+companyname +"</div>"+ address + '<br/>' + newpostnr + " " + by+ "<br/>" + "Tlf.: " + newphone + "<br/>" + newfax + newweb+"<a href='mailto:"+email+"'>"+email+"</a>"+'</div>' + image+'</div>';
//marker.openInfoWindowHtml(address);
//GEvent.addListener(marker, 'click',marker.openInfoWindowHtml(address));
GEvent.addListener(marker, "click", function()
{marker.openInfoWindowHtml(infoboxInfo);});
marker.markerType = markerType;
marker.title = companyname;
marker.address = address;
marker.postby = newpostnr+ " " + by;
marker.phone = newphone;
marker.fax = newfax;
marker.web = newweb;
marker.email = email;
}
}
}
);
}
}
Anyone any ideas ? How i said script is working as should if there is 5 markers or so … but shows only some of them when all are inserted ? Ideas ?
Yes you can do this as I did this in a previous project where the markers are loaded from the database (I use API v3 in this project but the concept is the same). Since the API accept like 5 requests at the same time from the same IP, I did a “marker queue”. When a marker can’t be placed because the API returns an error I put it in the queue and every second or so, I try to add the next marker from the queue until the queue is empty.
Just check the source of “gmaps3.js” in the previous link to see how I did this. If you have more questions, let me know.