简体   繁体   中英

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.

The Places API documentation, when using HTTPS requests, says that you need to add your Places API key (acquired through the Google API Console). The documentation also says that you must verify your identity with a credit card otherwise you are limited to 1000 request a day. Once verified you are allowed 100 000 requests per day.

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...

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...

Can anyone advise on this? Should I rework the code to use the HTTP request method so I can add the key there? Or is it possible, perhaps, to add the key to my initial load of the Google Maps JavaScript API?

Thanks in Advance,

Grammar.

You can add your API console key when loading the JS API as follows:

<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; it falls under the 25,000 map loads allowed in the v3 API. 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." (From the Usage Limits section of the Maps API FAQ)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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