Ta usługa lub funkcja ma stan „Stara”. Więcej informacji o stanie „Stary” znajdziesz w artykule Starsze usługi i funkcje. Aby przejść na interfejs Places API (nowy), przeczytaj przewodnik po migracji.
Autouzupełnianie miejsc (starsza wersja) używa tokenów sesji, aby grupować fazy zapytania i wyboru w ramach wyszukiwania autouzupełniania przez użytkownika w oddzielną sesję na potrzeby rozliczeń. Sesja rozpoczyna się, gdy użytkownik zacznie wpisywać zapytanie, a kończy, gdy wybierze miejsce i wywoła funkcję Szczegóły miejsca (starsza wersja). Każda sesja może zawierać kilka zapytań autouzupełniania, po których następuje wybór jednego miejsca. Klucze API używane do poszczególnych żądań w ramach sesji muszą należeć do tego samego projektu w konsoli Google Cloud. Po zakończeniu sesji token nie jest już ważny. Aplikacja musi wygenerować nowy token dla każdej sesji. Jeśli parametr sessiontoken zostanie pominięty lub jeśli ponownie użyjesz tokena sesji, sesja zostanie obciążona tak, jakby nie podano tokena sesji (za każde żądanie naliczane są osobne opłaty).
Zalecamy przestrzeganie tych wskazówek:
Używanie tokenów sesji we wszystkich sesjach autouzupełniania.
Upewnij się, że klucze interfejsu API używane do wszystkich żądań Autocomplete (starsza wersja) i Wyświetlanie szczegółów miejsca (starsza wersja) w ramach sesji należą do tego samego projektu w konsoli Google Cloud.
Pamiętaj, aby w przypadku każdej nowej sesji przekazać unikalny token sesji. Użycie tego samego tokena w więcej niż 1 sesji spowoduje, że za każde żądanie zostanie naliczona osobna opłata.
Opcjonalnie możesz pominąć token sesji autouzupełniania w żądaniu. Jeśli pominiesz token sesji, każde żądanie zostanie rozliczone osobno, co spowoduje użycie SKU Autocomplete - Per Request. Jeśli użyjesz ponownie tokena sesji, sesja zostanie uznana za nieprawidłową, a żądania zostaną obciążone opłatą tak, jakby nie podano tokena sesji.
Przykład
Gdy użytkownik wpisze zapytanie, po każdym naciśnięciu klawisza (a nie po każdym znaku) zostanie wywołane żądanie autouzupełniania i zwrócona lista możliwych wyników.
Gdy użytkownik wybierze coś z listy wyników, wybór ten jest traktowany jako żądanie, a wszystkie żądania wysłane podczas wyszukiwania są grupowane i liczone jako pojedyncze żądanie. Jeśli użytkownik wybierze miejsce, zapytanie jest bezpłatne, a opłata zostanie naliczona tylko za żądanie danych o miejscu. Jeśli użytkownik nie dokona wyboru w ciągu kilku minut od rozpoczęcia sesji, zostanie naliczona opłata tylko za zapytanie.
Przyjrzyjmy się temu procesowi z perspektywy aplikacji.
Użytkownik zaczyna wpisywać zapytanie, aby wyszukać „Paryż, Francja”.
Po wykryciu danych wejściowych użytkownika aplikacja tworzy nowy token sesji „Token A”.
Gdy użytkownik wpisze kilka znaków, interfejs API wysyła zapytanie o autouzupełnianie po każdym znaku, wyświetlając nową listę potencjalnych wyników:
"P"
"Par"
"Paris,"
"Paris, Fr"
Gdy użytkownik dokona wyboru:
Wszystkie żądania wynikające z zapytania są grupowane i dodawane do sesji reprezentowanej przez „Token A” jako pojedyncze żądanie.
Wybór użytkownika jest liczony jako żądanie szczegółów miejsca i dodawany do sesji reprezentowanej przez „Token A”.
Sesja została zakończona, a aplikacja odrzuciła „Token A”.
Więcej informacji o obliczaniu opłat za prośby o autouzupełnianie miejsc (starsza wersja) znajdziesz w sekcji Korzystanie i płatności.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-09-05 UTC."],[],[],null,["# Session Tokens\n\nSelect platform: [Android](/maps/documentation/places/android-sdk/session-tokens \"View this page for the Android platform docs.\") [iOS](/maps/documentation/places/ios-sdk/session-tokens \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/places-autocomplete#session_tokens \"View this page for the JavaScript platform docs.\") [Web Service](/maps/documentation/places/web-service/session-tokens \"View this page for the Web Service platform docs.\")\n\nPlace Autocomplete (Legacy) uses session tokens to group the query and selection\nphases of a user autocomplete search into a discrete session for billing\npurposes. The session begins when the user starts typing a query, and concludes\nwhen they select a place and a call to Place Details (Legacy) is made. Each session can\nhave multiple autocomplete queries, followed by one place selection. The API\nkey(s) used for each request within a session must belong to the same\nGoogle Cloud console project. Once a session has concluded, the token is no longer\nvalid; your app must generate a fresh token for each session. If the\n`sessiontoken` parameter is omitted, or if you reuse a session\ntoken, the session is charged as if no session token was provided (each request\nis billed separately).\n\nWe recommend the following guidelines:\n\n- Use session tokens for all autocomplete sessions.\n- [Generate a fresh token](#create-session-tokens) for each session.\n- Ensure that the API key(s) used for all Place Autocomplete (Legacy) and Place Details (Legacy) requests within a session belong to the same Google Cloud console project.\n- 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.\n\nYou can optionally omit the autocomplete session token from a request. If\nthe session token is omitted, each request is billed separately, triggering the\n\n[Autocomplete - Per Request](/maps/billing-and-pricing/sku-details#autocomplete-request-new-ess-sku)\n\n\nSKU. If you reuse a session token, the session is considered invalid and the\nrequests are charged as if no session token was provided.\n\nExample\n-------\n\nAs the user types a query, an autocomplete request is called every few\nkeystrokes (not per-character), and a list of possible results is returned.\nWhen the user makes a selection from the result list, the selection counts as\na request, and all of the requests made during the search are bundled and\ncounted as a single request. If the user selects a place, the search query is\navailable at no charge, and only the Place data request is charged. If the user does not make a\nselection within a few minutes of the beginning of the session, only the\nsearch query is charged.\n\nLet's examine this flow of events from the perspective of an app.\n\n1. A user begins typing a query to search for \"Paris, France\".\n2. Upon detecting user input, the app creates a new session token, \"Token A\".\n3. As the user types, the API makes an autocomplete request every few characters, displaying a new list of potential results for each: \n \"P\" \n \"Par\" \n \"Paris,\" \n \"Paris, Fr\" \n4. When the user makes a selection:\n - All requests resulting from the query are grouped and added to the session represented by \"Token A\", as a single request.\n - The user's selection is counted as a Place Detail request, and added to the session represented by \"Token A\".\n5. The session is concluded, and the app discards \"Token A\".\n\nFor more information about how Place Autocomplete (Legacy) requests are billed, see\n\n[Usage and Billing](/maps/documentation/places/android-sdk/usage-and-billing).\n\nCreate session tokens\n---------------------\n\n\nTo create a session token, call\n[`AutocompleteSessionToken.newInstance()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/model/AutocompleteSessionToken#newInstance())."]]