简体   繁体   English

Google Places JavaScript API v3,如何将API密钥添加到请求中?

[英]Google Places JavaScript API v3, how can I add my API key to requests?

I've got a web application using the Google Maps JavaScript API(v3) and I'm hitting the Places API using the JavaScript version as well. 我有一个使用Google Maps JavaScript API(v3)的网络应用程序,我也使用JavaScript版本访问Places API。

The Places API documentation, when using HTTPS requests, says that you need to add your Places API key (acquired through the Google API Console). Places API文档在使用HTTPS请求时表示您需要添加Places API密钥(通过Google API控制台获取)。 The documentation also says that you must verify your identity with a credit card otherwise you are limited to 1000 request a day. 文档还说明您必须使用信用卡验证您的身份,否则您每天只能获得1000个请求。 Once verified you are allowed 100 000 requests per day. 经过验证,您每天可以获得10万个请求。

There is no documentation, however, that says how to add your API key to the JavaScript object you pass into the google.maps.places.PlacesService.search() method... 但是,没有文档说明如何将API密钥添加到传递给google.maps.places.PlacesService.search()方法的JavaScript对象中......

My client is very concerned with this daily limit, as the app is a kiosk that will be part of a huge trade show where it's likely that the Places API will be pinged more than 1000 times throughout the day... 我的客户非常关注这个每日限额,因为该应用程序是一个信息亭,将成为一个巨大的贸易展览的一部分,其中Places API可能会在一天内被ping超过1000次......

Can anyone advise on this? 任何人都可以就此提出建议吗? Should I rework the code to use the HTTP request method so I can add the key there? 我应该重新编写代码以使用HTTP请求方法,以便我可以在那里添加密钥吗? Or is it possible, perhaps, to add the key to my initial load of the Google Maps JavaScript API? 或者,是否可以将键添加到我最初加载的Google Maps JavaScript API中?

Thanks in Advance, 提前致谢,

Grammar. 语法。

You can add your API console key when loading the JS API as follows: 您可以在加载JS API时添加API控制台密钥,如下所示:

<script type="text/javascript"
      src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE">

However, I don't believe the JS Places service is subject to the same limit; 但是,我不认为JS Places服务受到同样的限制; it falls under the 25,000 map loads allowed in the v3 API. 它属于v3 API中允许的25,000个地图加载。 In addition, to soothe your client's mind, you can note that for the JS API, "In order to accommodate sites that experience short term spikes in usage (eg. a news gathering organisation or a site that briefly goes viral), the usage limits will only be enforced once a site has exceeded the limits for 90 consecutive days." 此外,为了安抚客户的想法,您可以注意到,对于JS API,“为了容纳在使用中遇到短期高峰的网站(例如新闻采集组织或短暂传播的网站),使用限制只有在网站连续90天超过限制时才会执行。“ (From the Usage Limits section of the Maps API FAQ) (来自Maps API常见问题解答的使用限制部分)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM