开发者

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 wh开发者_StackOverflow社区ich show up.

Here is an online example to show the problem.


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!


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.


If your list of addresses is finite, you should consider putting them into a Google spreadsheet and then making them into a Google Fusion Table http://www.google.com/fusiontables/public/tour/index.html which permits you to export as KML.

Once your data is in a Fusion Table you have the option to geocode the addresses. This takes some time, like a few minutes for say, 100 addresses. Even then, there will be some addresses it fails to find, or locates incorrectly. But these will be wildly obvious because they show up on the preview kml map. For example I had some UK addresses to geocode in Cambridge but they were resolved by Google to Cambridge in the US. (I just appended 'UK' to every address and ran it again, and it worked fine).

So: Google looking up addresses on the fly, as NgM has explained is not foolproof.
Google looking up adddresses on the fly is not consistent, as you have found out. Google Fusion Tables permits Google to do a thorough job, for you to quality review those choices and run them again if you wish, or override them and then most importantly for Google to cache those results for you permanently (well, as permanent as a Beta Google project can be adjudged to be ...)

But as I say, only if you list of addresses is finite.

You get geocoded, you can download locally, and you win kml files too, if you wanted to diversify into using that.


Just a suggestion: there is no valid doctype or encoding in the HTML source (demo page). This leads to strange behaviour. Try prepending

<!DOCTYPE html>

to HTML source and a header (btw. the closing head tag is missing)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

to provide jQuery and gmaps with a valid header, charset and document type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜