3

The new Places API Billing defines Sessions for merging Autocomplete and Place details requests, but the docs just say the API will merge requests with the same Session Token, made within some minutes.

I find this very vague!

Do we have to generate new Session Tokens or can we reuse the same and the API will group them anyway within time-windows?

Do we have to be aware of the lifespan of the Session Tokens?

Can the Session Tokens be any kind of string?

Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
  • It seems to be described in the [documentation](https://developers.google.com/maps/documentation/javascript/places-autocomplete#session_tokens). – geocodezip Jan 30 '19 at 02:49
  • I didn't find this in the email Google sent me about the new API, but anyway this docs doesn't answer my questions. 1 - What does `A session consists of the keystrokes used to resolve user input to a place` even mean? Where does a Session start and where does it end? 2 - If I am not using the Session Token generated by the SDK (like I am making a new SDK for another language) and I need to include the Session as a string, can it be any kind of string? – Michel Feinstein Jan 30 '19 at 02:57
  • Probably this information might be useful: https://stackoverflow.com/a/50452233/5140781 – xomena Jan 30 '19 at 20:34
  • Thank you, but even there it isn't clear what defines the start and the end of a session – Michel Feinstein Jan 30 '19 at 20:39
  • You define start and end of the session. Once you start typing you should generate unique session token in case if you use web service. If you use Maps JavaScript API session token is generated for you automatically. Once you selected item and requested place details the session is ended. I think you can reuse the same token, but Google didn't document exact time duration for one session. So it safer regenerate session token each time user selected an item and requested place details. – xomena Jan 30 '19 at 20:44
  • Have also look at https://developers.google.com/places/web-service/autocomplete#session_tokens – xomena Jan 30 '19 at 20:45
  • So I can group requests for "p" "pa" "par" "pary" "par" "pari" for Paris with a typo in between and then only generate a new Session once my user clicks to see Paris details OR a timer says I should generate a new Session? For example my user typed Paris didn't click on anything and 4 minutes later he erased the text and typed something else (triggering searches for intermediary text while Paris is being erased and the new location being written) – Michel Feinstein Jan 30 '19 at 20:51

1 Answers1

1

Google has all this answers, but is spread over a lot of different places and can be hard to find. To answer all 3 of your questions:

Do we have to generate new Session Tokens or can we reuse the same and the API will group them anyway within time-windows?

The session tokens cannot be reused from one session to the other.

Do we have to be aware of the lifespan of the Session Tokens?

The session begins when the user starts typing and ends when they select a place and you call the detail API. Once that happens you must generate a new session token for each new call to the autocomplete API.

Can the Session Tokens be any kind of string?

The Google Places API provides a class that you can use, but you don't have to. The class Google provides is called AutocompleteSessionToken it can be used liked this:

var token = new google.maps.places.AutocompleteSessionToken()

But you can also use your own string. See Google's recommendation

All this info is straight from the Google Docs, see below:

Place Autocomplete uses session tokens to group the query and selection phases of a user autocomplete search into a discrete session for billing purposes. The session begins when the user starts typing a query, and concludes when they select a place. Each session can have multiple queries, followed by one place selection. Once a session has concluded, the token is no longer valid; your app must generate a fresh token for each session. We recommend using session tokens for all autocomplete sessions. If the sessiontoken parameter is omitted, or if you reuse a session token, the session is charged as if no session token was provided (each request is billed separately).

Source: Google Documentation

derickito
  • 695
  • 7
  • 25
  • I found there's also a time-span where the session is active, but Google doesn't want to document it for now... And libraries don't help yet for people developing for Flutter. – Michel Feinstein Apr 27 '19 at 23:13
  • If this is indeed the case it is undocumented. I would think they would set some sort of reasonable time-span for all these grouped calls to occur since you can't expect hours to go by from when the user types to when they select a place. It'd still be nice to know what that limit is. I'm assuming they don't publish it so people don't start gaming the system somehow. – derickito Apr 28 '19 at 03:25
  • Exactly, and for what I have heard of its something around 3 minutes or so – Michel Feinstein Apr 28 '19 at 03:28
  • @mFeinstein if you're using flutter I just made a video showing how to add session tokens to autocomplete requests https://youtu.be/mzqgVWli6k0 - note I'm not using a package and simply making the api requests to the places api – projectmind Oct 27 '19 at 21:27
  • Thanks, but I heard some time ago that the Google Maps team was going to be focusing on Flutter, so there might come a package soon – Michel Feinstein Oct 27 '19 at 21:37