Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sessiontoken and sparse fields #867

Merged
merged 4 commits into from
Jul 19, 2018
Merged

Conversation

Gnito
Copy link
Contributor

@Gnito Gnito commented Jul 12, 2018

This is a reaction to Google Maps pricing change:

  • Added sessionToken to Autocomplete calls (otherwise calls are prices separately)
  • Use sparse fields for place details call (otherwise all the data is returned and it costs more)

@Gnito Gnito requested a review from lyyder July 12, 2018 19:10
@@ -213,6 +217,7 @@ class LocationAutocompleteInput extends Component {
this.setState({ highlightedIndex: -1 });

if (!newValue) {
this.autocompleteSessionToken = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the token need to be cleared out when user clears input when the place details have not been retrieved? E.g. input "Hel" -> delete all -> input "Espoo" -> click the item? Is this one or two sessions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bladealslayer that's what I understood from docs, but I'm not sure. Should be asked from Google guys. Those docs just say that if the same session token is used in several sessions/occasions, all the calls are handled individually -> it cancels the price reduction of the token.

I assume that there's an undisclosed lifetime on those tokens - but since it's undisclosed, I assume that the desired behavior is that one character search "sequence" group is one session: "h", "he", "hel" -> "Helsinki".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developers.google.com/maps/documentation/javascript/places-autocomplete#session_tokens
"Warning: Be sure to pass a unique session token for each new session. Using the same token for more than one session will result in each request being billed individually. Note that the Autocomplete Widget handles sessions automatically (you don't need to do anything additional)."

@@ -47,9 +47,10 @@ export const getPlaceDetails = (placeId, sessionToken) =>
const serviceStatus = window.google.maps.places.PlacesServiceStatus;
const el = document.createElement('div');
const service = new window.google.maps.places.PlacesService(el);
const fields = ['address_component', 'formatted_address', 'geometry', 'place_id'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the place_id known already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it doesn't hurt to have that returned also (it's part of the basic fields => same pricing). Anyway, id's included to the return object makes them easier to be reused in Redux store if that kind of feature is needed.

Copy link
Contributor

@lyyder lyyder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Have you checked that the session token is always generated for every autocomplete "session"? Or does the Google Maps SDK handle that?

Note: this might be reversed, if there's some time limit for tokens)
@Gnito Gnito merged commit f97cf48 into master Jul 19, 2018
@Gnito Gnito deleted the add-sessiontoken-and-sparse-fields branch July 19, 2018 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants