javascript 如何检测 Google 地图中已达到每天 25000 个请求的限制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8665696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:10:24  来源:igfitidea点击:

How to detect that the 25000 request per day limit has been reached in Google Maps?

javascriptgoogle-maps-api-3google-api

提问by Guillaume Flandre

I'm working on a website using the Google Maps Javascript API v3.

我正在使用 Google Maps Javascript API v3 开发一个网站。

The free version of the API is limited by 25000 requests a day. But what happens if this limit is reached?

API 的免费版本限制为每天 25000 个请求。但是如果达到这个限制会发生什么?

Is there a way to detect that the request limit has been reached so a fallback Google Maps Image API map can be displayed instead?

有没有办法检测已达到请求限制,以便可以显示后备 Google Maps Image API 地图?

回答by jasonyork

The usage limit is based on site or application, not the client IP address.

使用限制基于站点或应用程序,而不是客户端 IP 地址。

You can use the Google API console to monitor your usage if you add an API key to each of your map requests. I have not seen a way to query the usage programmatically. https://code.google.com/apis/console

如果您向每个地图请求添加 API 密钥,则可以使用 Google API 控制台来监控您的使用情况。我还没有看到以编程方式查询使用情况的方法。 https://code.google.com/apis/console

Per the comment below by @alds, it does appear that JS Maps API v3 and Static Maps API are separate services, therefore having separate request limits. Falling back to a static Google map image could help.

根据@alds 下面的评论,JS Maps API v3 和 Static Maps API 似乎是单独的服务,因此具有单独的请求限制。回到静态谷歌地图图像可能会有所帮助。

This also explains the usage limits in better detail: http://googlegeodevelopers.blogspot.com/2011/11/understanding-how-maps-api-usage-limits.html

这也更详细地解释了使用限制:http: //googlegeodevelopers.blogspot.com/2011/11/understanding-how-maps-api-usage-limits.html

回答by PaulC

You cannot detect via the API that the request limit has been reached. There are no events that are fired and the API does not expose a function or property to determine that the API quota has been reached.

您无法通过 API 检测到已达到请求限制。不会触发任何事件,并且 API 不会公开用于确定已达到 API 配额的函数或属性。

Google has decided that this is not a feature they will implement.

Google 已决定这不是他们将实施的功能。

https://issuetracker.google.com/issues/35830575#comment12

https://issuetracker.google.com/issues/35830575#comment12

回答by alds

@kilogauss I would disagree that falling back to static Google Map is not an option.

@kilogauss 我不同意退回到静态谷歌地图不是一种选择。

According to https://developers.google.com/maps/faq#usagelimits

根据https://developers.google.com/maps/faq#usagelimits

"Web sites and applications using the Google Maps API may at no cost generate up to 25,000 map loads per day FOR EACHservice"(capitalization and boldface mine).

“使用 Google Maps API 的网站和应用程序每天可以免费为每个服务生成多达 25,000 次地图加载”(我的大写和黑体字)。

And on https://developers.google.com/maps/faq#usage_pricing, you can see that JS Maps API v3 and Static Maps API are separate services.

https://developers.google.com/maps/faq#usage_pricing 上,您可以看到 JS Maps API v3 和 Static Maps API 是独立的服务。