开发者

Google Maps API direction limit

开发者 https://www.devze.com 2022-12-16 11:45 出处:网络
I\'ve used the Google Maps API to make a map that displays direction polylines for multiple users to a common destination. So each user has their own polyline displayed on the map at the same time.

I've used the Google Maps API to make a map that displays direction polylines for multiple users to a common destination. So each user has their own polyline displayed on the map at the same time.

The problem is that there appears to be a limit of how many polylines get returned. When I have more than about 10 users, i stop receiving polyline data. (the last users to be added to the map don't get a polyline). I might point out that the load function still appe开发者_StackOverflow中文版ars to work (the error event listener is not being called), but i either don't get polyline data, or it refuses to draw to the map.

The number of polylines that get drawn is slightly different every time which makes me think google just doesn't like receiving so many requests at once from the same user but i can't be certain.

Does anyone have any ideas how to get around this? I've tried providing latitudes and longitudes instead of address strings to try and cut down on the workload but it doesn't seem to have any effect on the number of polylines that get drawn.


According to the Google Maps API blog, you should be able to make 10,000 GDirections requests a day without being throttled by Google. However I found a post on the Google Maps API Group that suggests there is a separate throttling mechanism that will return 620 HTTP errors based on the rate that you make requests.

From your question, it looks like your error listener is not being called, so this doesn't quite fit. But I haven't found a official description of this behavior from Google, so I am not sure.

Are you able to buffer your GDirections requests and reduce the rate you are making them? This might be a good test to see if you are being affected by a request rate throttling mechanism.


I just did something fairly simple as shown below. I create an array of all the directions I want to add beforehand. I loop through my directions, add a marker (I add a marker separate to the direction so that there is always a marker even if the direction fails to draw), then I call the setTimeout function to schedule the direction call so that Google doesn't get them all at once. Then I increase the value of milliseconds by about 250 (might have to play around with this value).

var milliseconds = 0;
for(i in directions){
    addMarker(directions[i]); //I place the marker separate to the direction so that there is always a marker even if the direction fails to draw.

    setTimeout( function(){
                  addDirection(directions[directionCounter]); //This is my function that makes the direction request to Google
                  directionCounter++;
                }
                , milliseconds);

    milliseconds += 250;
}

Hope this is helps.

0

精彩评论

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