React-native-google-places-autocomplete: Question: what about new billing across Google Places API?

Created on 19 Jul 2018  路  9Comments  路  Source: FaridSafi/react-native-google-places-autocomplete

What about new billing across Google Places? How it affect in this plugin?

Is there any way like Per session (sessionToken), to minimize these costs?

Thanks in advance

Most helpful comment

Just create an access token using uuid v4, as suggested by google documentation:

const createPlacesAutocompleteSessionToken = (a) => {
  return a
    ? (a ^ Math.random() * 16 >> a / 4).toString(16)
    : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, createPlacesAutocompleteSessionToken);
};

I do that on componentDidMount and probably you should refresh it on suggestion select (I destroy the component on select, so I don't need that):

this.placesAutocompleteToken = createPlacesAutocompleteSessionToken()

Then pass it in query prop:

query={{
  ...,
  sessiontoken: this.placesAutocompleteToken,
}}

Check the api call in network tab, the token will appear.

All 9 comments

It will affect it as any other website or app. The component is making http requests using your api key, so you get billed if the limit is reached.

It would be great to have an option to enable sessionToken.

Last paragraph in this page explains how to implement it, it's very easy:
https://cloud.google.com/maps-platform/user-guide/pricing-changes
And you should also reset the token on selection.

EDIT: I just got that this library does not use javascript api but web api. Even simpler we can handle sessiontoken as query params, without modification. I just successfully implemented it using uuid v4 as suggested.

PRs are welcome

Hi @marconucara,
Could you give an example of how you added the sessionToken to autocomplete requests?
Would be really appreciated!

Just create an access token using uuid v4, as suggested by google documentation:

const createPlacesAutocompleteSessionToken = (a) => {
  return a
    ? (a ^ Math.random() * 16 >> a / 4).toString(16)
    : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, createPlacesAutocompleteSessionToken);
};

I do that on componentDidMount and probably you should refresh it on suggestion select (I destroy the component on select, so I don't need that):

this.placesAutocompleteToken = createPlacesAutocompleteSessionToken()

Then pass it in query prop:

query={{
  ...,
  sessiontoken: this.placesAutocompleteToken,
}}

Check the api call in network tab, the token will appear.

Great, and thanks for such a quick response!

thanks @marconucara

Really helpful!!

what is this a parameter a in the function

Heads up that you also need to pass the sessiontoken in the Details query for any of this to have an effect, afaik.

```
query={{
...,
sessiontoken: this.placesAutocompleteToken,
}}
GooglePlacesDetailsQuery={{
...,
sessiontoken: this.placesAutocompleteToken,
}}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aymkin picture aymkin  路  4Comments

DennisMuchiri picture DennisMuchiri  路  4Comments

akhlopyk picture akhlopyk  路  3Comments

frankfaustino picture frankfaustino  路  4Comments

yashwanth15 picture yashwanth15  路  3Comments