Places Autocomplete Service

AutocompleteService class

google.maps.places.AutocompleteService class

Contains methods related to retrieving Autocomplete predictions.

Access by callingconst {AutocompleteService} = await google.maps.importLibrary( "places" ).SeeLibraries in the Maps JavaScript API.

AutocompleteService
AutocompleteService()
Parameters:None
Creates a new instance of theAutocompleteService.
getPlacePredictions
getPlacePredictions(request[, callback])
Parameters:
Retrieves place autocomplete predictions based on the supplied autocomplete request.
getQueryPredictions
getQueryPredictions(request, callback)
Parameters:
Return Value:None
Retrieves query autocomplete predictions based on the supplied query autocomplete request.

AutocompletionRequest interface

google.maps.places.AutocompletionRequest interface

An Autocompletion request to be sent toAutocompleteService.getPlacePredictions.

input
Type:string
The user entered input string.
boundsoptional
Bounds for prediction biasing. Predictions will be biased towards, but not restricted to, the givenbounds.Bothlocationandradiuswill be ignored ifboundsis set.
componentRestrictionsoptional
The component restrictions. Component restrictions are used to restrict predictions to only those within the parent component. For example, the country.
languageoptional
Type:stringoptional
A language identifier for the language in which the results should be returned, if possible. Results in the selected language may be given a higher ranking, but suggestions are not restricted to this language. See thelist of supported languages.
locationoptional
Type:LatLngoptional
Location for prediction biasing. Predictions will be biased towards the givenlocationandradius.Alternatively,boundscan be used.
locationBiasoptional
Type:LocationBiasoptional
A soft boundary or hint to use when searching for places.
locationRestrictionoptional
Type:LocationRestrictionoptional
Bounds to constrain search results.
offsetoptional
Type:numberoptional
The character position in the input term at which the service uses text for predictions (the position of the cursor in the input field).
originoptional
Type:LatLng|LatLngLiteraloptional
The location whereAutocompletePrediction.distance_metersis calculated from.
radiusoptional
Type:numberoptional
The radius of the area used for prediction biasing. Theradiusis specified in meters, and must always be accompanied by alocationproperty. Alternatively,boundscan be used.
regionoptional
Type:stringoptional
A region code which is used for result formatting and for result filtering. It does not restrict the suggestions to this country. The region code accepts accTLD ( "top-level domain" )two-character value. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland" ).
sessionTokenoptional
Unique reference used to bundle individual requests into sessions.
typesoptional
Type:Array<string>optional
The types of predictions to be returned. For supported types, see thedeveloper's guide.If no types are specified, all types will be returned.

AutocompleteResponse interface

google.maps.places.AutocompleteResponse interface

An Autocomplete response returned by the call toAutocompleteService.getPlacePredictionscontaining a list ofAutocompletePredictions.

predictions

QueryAutocompletionRequest interface

google.maps.places.QueryAutocompletionRequest interface

A QueryAutocompletion request to be sent to theQueryAutocompleteService.

input
Type:string
The user entered input string.
boundsoptional
Bounds for prediction biasing. Predictions will be biased towards, but not restricted to, the givenbounds.Bothlocationandradiuswill be ignored ifboundsis set.
locationoptional
Type:LatLngoptional
Location for prediction biasing. Predictions will be biased towards the givenlocationandradius.Alternatively,boundscan be used.
offsetoptional
Type:numberoptional
The character position in the input term at which the service uses text for predictions (the position of the cursor in the input field).
radiusoptional
Type:numberoptional
The radius of the area used for prediction biasing. Theradiusis specified in meters, and must always be accompanied by alocationproperty. Alternatively,boundscan be used.

AutocompleteSessionToken class

google.maps.places.AutocompleteSessionToken class

Represents a session token used for tracking an autocomplete session, which can be a series ofAutocompleteService.getPlacePredictionscalls followed by a singlePlacesService.getDetailscall.

Access by callingconst {AutocompleteSessionToken} = await google.maps.importLibrary( "places" ).SeeLibraries in the Maps JavaScript API.

AutocompleteSessionToken
AutocompleteSessionToken()
Parameters:None
Creates a new instance ofAutocompleteSessionToken.

ComponentRestrictions interface

google.maps.places.ComponentRestrictions interface

Defines the component restrictions that can be used with the autocomplete service.

countryoptional
Type:string|Array<string>optional
Restricts predictions to the specified country (ISO 3166-1 Alpha-2 country code, case insensitive). For example,'us','br',or'au'.You can provide a single one, or an array of up to five country code strings.

AutocompletePrediction interface

google.maps.places.AutocompletePrediction interface

Represents a single autocomplete prediction.

description
Type:string
This is the unformatted version of the query suggested by the Places service.
matched_substrings
A set of substrings in the place's description that match elements in the user's input, suitable for use in highlighting those substrings. Each substring is identified by an offset and a length, expressed in unicode characters.
place_id
Type:string
A place ID that can be used to retrieve details about this place using the place details service (seePlacesService.getDetails).
structured_formatting
Structured information about the place's description, divided into a main text and a secondary text, including an array of matched substrings from the autocomplete input, identified by an offset and a length, expressed in unicode characters.
terms
Information about individual terms in the above description, from most to least specific. For example, "Taco Bell", "Willitis", and "CA".
types
Type:Array<string>
An array of types that the prediction belongs to, for example'establishment'or'geocode'.
distance_metersoptional
Type:numberoptional
The distance in meters of the place from theAutocompletionRequest.origin.

QueryAutocompletePrediction interface

google.maps.places.QueryAutocompletePrediction interface

Represents a single Query Autocomplete prediction.

description
Type:string
This is the unformatted version of the query suggested by the Places service.
matched_substrings
A set of substrings in the place's description that match elements in the user's input, suitable for use in highlighting those substrings. Each substring is identified by an offset and a length, expressed in unicode characters.
terms
Information about individual terms in the above description. Categorical terms come first (for example, "restaurant" ). Address terms appear from most to least specific. For example, "San Francisco", and "CA".
place_idoptional
Type:stringoptional
Only available if prediction is a place. A place ID that can be used to retrieve details about this place using the place details service (seePlacesService.getDetails).

PredictionTerm interface

google.maps.places.PredictionTerm interface

Represents a prediction term.

offset
Type:number
The offset, in unicode characters, of the start of this term in the description of the place.
value
Type:string
The value of this term, for example, "Taco Bell".

PredictionSubstring interface

google.maps.places.PredictionSubstring interface

Represents a prediction substring.

length
Type:number
The length of the substring.
offset
Type:number
The offset to the substring's start within the description string.

StructuredFormatting interface

google.maps.places.StructuredFormatting interface

Contains structured information about the place's description, divided into a main text and a secondary text, including an array of matched substrings from the autocomplete input, identified by an offset and a length, expressed in unicode characters.

main_text
Type:string
This is the main text part of the unformatted description of the place suggested by the Places service. Usually the name of the place.
main_text_matched_substrings
A set of substrings in the main text that match elements in the user's input, suitable for use in highlighting those substrings. Each substring is identified by an offset and a length, expressed in unicode characters.
secondary_text
Type:string
This is the secondary text part of the unformatted description of the place suggested by the Places service. Usually the location of the place.