Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery and Google Maps: Cannot display more than 11 markers

I'm using a great jQuery plugin called GMaps3 to display a map on a website. I'm trying to add markers with the .addMarker method (I only know the address, not the lat and long) but it only adds 11 markers max in my example.

I am trying to figure out why certain markers are not displayed while others are.

Update: The number of markers shown is not constant. I edited one of the address strings (thanks NgM) to make it more specific and the number of markers shown increased to 11. Other markers won't show up though, even if they are non-ambiguous. It's the first dozen or so which show up.

Here is an online example to show the problem.

like image 528
bootsmaat Avatar asked Feb 23 '23 15:02

bootsmaat


2 Answers

I had the exact same problem and I finally figured out how to solve it. The problem is occurring because geocoding does not allow a lot of simultaneous requests. So this is where a the setInterval() javascript method comes in handy.

Just add something like this to your code:

counter = 0,
timer = setInterval(function () {
createMarkers(map, postcodes);
    counter++
    if (counter3 === postcodes.length) {
        clearInterval(timer);
    }
}, 1000);

The CreateMarkers() function is where the markers are created from an Array. So after each postcode has been geocoded and applied to the map the script waits 1 second and then continues with the next postcode.

I hope this helps, I spent ages wondering why it only let 11 markers on the map at one time!

like image 145
mat Avatar answered Feb 26 '23 05:02

mat


This is because some of your addresses do not resolve to a specific address.

You have entries like: "Campus Pappelallee, 14406 Potsdam, Germany"

Google Maps, when you search for this address, has no way of knowing where you want it to select. There are over 1,500 suggestions.

The reason you see markers for addresses like:

Boulevard James-Fazy 15, 1201 Genève, Switzerland

Is because Google Maps can find that address and that search only returns one result (IE the exact place you had in mind).

For all addresses that Google Maps can't resolve correctly and you know it exists at the address you listed then simply use the long/lat instead of address. You said you do not happen to know a more specific address though for these entries so I suggest you spend some time figuring out where it is exactly you want the marker to be placed.

like image 37
Mike Veigel Avatar answered Feb 26 '23 03:02

Mike Veigel