Javascript Google maps, displays only 10 markers out of 100. Is there a limit?

孤街醉人 提交于 2019-12-02 03:06:54

Yes, there is a rate limit, which isn't too well documented. 9-10 requests per second? If you check the error status, it's called OVER_QUERY_LIMIT. With 100 markers, I don't think the common waiting technique will do you much good, because you have a lot of markers. It's best to geocode once, save the LatLngs and use them.

If you're brave, you can try:

setTimeout(function(){
  geocoder.geocode(geoOptions, createGeocodeCallback(list[i], map));
}, 200*i);

I don't know why everyone uses 200 ms, maybe from trial and error? You can try 150, or 100. Still, at 100 ms it will take you 10 seconds to load 100 markers. Another idea I read about is to query in batches. Geocode ten, wait, then another ten.

An alternate function you can try is sleep.

function sleep(milliSeconds) {
  var startTime = new Date().getTime();
  while (new Date().getTime() < startTime + milliSeconds);
}
Andrew Leach

Lilina is right about the rate limit, but it's possible to vary the rate depending on whether you fall foul of it or not. 200ms is likely to OK all the time, but see also this linked question where there's an example of a varying rate which starts faster than that (and is actually only slowed down to around 150ms).

The problem recounted there is exactly the same as yours.

Google Map V3 : Only some markers are displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!