PlaceAutocompleteElement class
google.maps.places
. PlaceAutocompleteElement
class
PlaceAutocompleteElement is an HTMLElement
subclass which provides a UI component for the Places Autocomplete API.
Custom element: <gmp-place-autocomplete included-primary-types="type1 type2 type3..." included-region-codes="c1 c2 c3..." name="string" origin="lat,lng|lat,lng,altitude" requested-language="string" requested-region="string" unit-system="metric|imperial" types="type1 type2 type3..."></gmp-place-autocomplete>
This class extends HTMLElement
.
This class implements PlaceAutocompleteElementOptions
.
Access by calling const {PlaceAutocompleteElement} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Constructor
PlaceAutocompleteElement(options)
-
options
:PlaceAutocompleteElementOptions
Properties
Array
<string> optional
A Place is only returned if its primary type is included in this list. Up to 5 values can be specified. If no types are specified, all Place types are returned.
-
<gmp-place-autocomplete included-primary-types="type1 type2 type3..."></gmp-place-autocomplete>
Array
<string> optional
locationRestriction
and includedRegionCodes
are set, the results will be located in the area of intersection.-
<gmp-place-autocomplete included-region-codes="c1 c2 c3..."></gmp-place-autocomplete>
LocationBias
optional
LocationRestriction
optional
string optional
-
<gmp-place-autocomplete name="string"></gmp-place-autocomplete>
LatLng
| LatLngLiteral
| LatLngAltitude
| LatLngAltitudeLiteral
optional
-
<gmp-place-autocomplete origin="lat,lng|lat,lng,altitude"></gmp-place-autocomplete>
string optional
-
<gmp-place-autocomplete requested-language="string"></gmp-place-autocomplete>
string optional
.co.uk
) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland").-
<gmp-place-autocomplete requested-region="string"></gmp-place-autocomplete>
UnitSystem
optional
-
<gmp-place-autocomplete unit-system="metric|imperial"></gmp-place-autocomplete>
ComponentRestrictions
optional
Array
<string> optional
-
<gmp-place-autocomplete types="type1 type2 type3..."></gmp-place-autocomplete>
Parts |
|
---|---|
prediction-item
|
An item in the drop down of predictions that represents a single prediction.
|
prediction-item-icon
|
The icon displayed to the left of each item in the list of predictions.
|
prediction-item-main-text
|
A part of prediction-item that is the main text of the prediction. For geographic locations, this contains a place name, like 'Sydney', or a street name and number, like '10 King Street'. By default, the prediction-item-main-text is colored black. If there is any additional text in the prediction-item, it is outside prediction-item-main-text and inherits its styling from prediction-item. It is colored gray by default. The additional text is typically an address.
|
prediction-item-match
|
The part of the returned prediction that matches the user’s input. By default, this matched text is highlighted in bold text. Note that the matched text may be anywhere within prediction-item. It is not necessarily part of prediction-item-main-text.
|
prediction-item-selected
|
The item when the user navigates to it via the keyboard. Note: Selected items will be affected by both this part styles and also the prediction-item part styles.
|
prediction-list
|
The visual element containing the list of predictions returned by the Place Autocomplete service. This list appears as a dropdown list below the PlaceAutocompleteElement.
|
Methods
addEventListener(type, listener[, options])
-
type
:string
A case-sensitive string representing the event type to listen for. -
listener
:EventListener | EventListenerObject
The object that receives a notification. This must be a function or an object with the handleEvent method -
options
:boolean| AddEventListenerOptions optional
See options . Custom events only supportcapture
andpassive
.
void
removeEventListener(type, listener[, options])
-
type
:string
A string which specifies the type of event for which to remove an event listener. -
listener
:EventListener | EventListenerObject
The event listener of the event handler to remove from the event target. -
options
:boolean| EventListenerOptions optional
See options .
void
Events
function(errorEvent)
-
errorEvent
:Event
function(placePredictionSelectEvent)
-
placePredictionSelectEvent
:PlacePredictionSelectEvent
function(placeAutocompletePlaceSelectEvent)
-
placeAutocompletePlaceSelectEvent
:PlaceAutocompletePlaceSelectEvent
PlaceAutocompleteElementOptions interface
google.maps.places
. PlaceAutocompleteElementOptions
interface
Options for constructing a PlaceAutocompleteElement. For the description of each property, refer to the property of the same name in the PlaceAutocompleteElement class.
Properties |
|
---|---|
|
Type:
ComponentRestrictions
optional
|
|
Type:
Array
<string> optional
|
|
Type:
Array
<string> optional
|
locationBias
optional
|
Type:
LocationBias
optional
|
locationRestriction
optional
|
Type:
LocationRestriction
optional
|
name
optional
|
Type:
string optional
|
|
Type:
LatLng
| LatLngLiteral
| LatLngAltitude
| LatLngAltitudeLiteral
optional
|
requestedLanguage
optional
|
Type:
string optional
|
|
Type:
Array
<string> optional
|
|
Type:
UnitSystem
optional
|
PlaceAutocompletePlaceSelectEvent class
google.maps.places
. PlaceAutocompletePlaceSelectEvent
class
This event is created after the user selects a place with the Place Autocomplete Element. Access the selection with event.place
.
This class extends Event
.
Access by calling const {PlaceAutocompletePlaceSelectEvent} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Properties |
|
---|---|
|
Type:
Place
|
PlacePredictionSelectEvent class
google.maps.places
. PlacePredictionSelectEvent
class
This event is created after the user selects a prediction item with the PlaceAutocompleteElement. Access the selection with event.placePrediction
.
This class extends Event
.
Access by calling const {PlacePredictionSelectEvent} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Properties |
|
---|---|
placePrediction
|
Type:
PlacePrediction
|
PlaceAutocompleteRequestErrorEvent class
google.maps.places
. PlaceAutocompleteRequestErrorEvent
class
This event is emitted by the PlaceAutocompleteElement when there is an issue with the network request.
This class extends Event
.
Access by calling const {PlaceAutocompleteRequestErrorEvent} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
PlaceDetailsElement class
google.maps.places
. PlaceDetailsElement
class
An HTML element that displays details for a place. Use the configureFromPlace()
or configureFromLocation()
methods to specify the content to be rendered. To use the Place Details Element, enable the Places UI Kit API
for your project in the Google Cloud console.
Custom element: <gmp-place-details size="small"></gmp-place-details>
This class extends HTMLElement
.
This class implements PlaceDetailsElementOptions
.
Access by calling const {PlaceDetailsElement} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Constructor
PlaceDetailsElement([options])
-
options
:PlaceDetailsElementOptions optional
Properties
Place
optional
Place
object containing the ID, location, and viewport of the currently rendered place. PlaceDetailsSize
optional
PlaceDetailsSize.X_LARGE
.-
<gmp-place-details size="small"></gmp-place-details>
-
<gmp-place-details size="medium"></gmp-place-details>
-
<gmp-place-details size="large"></gmp-place-details>
-
<gmp-place-details size="x-large"></gmp-place-details>
Methods
addEventListener(type, listener[, options])
-
type
:string
A case-sensitive string representing the event type to listen for. -
listener
:EventListener | EventListenerObject
The object that receives a notification. This must be a function or an object with the handleEvent method -
options
:boolean| AddEventListenerOptions optional
See options . Custom events only supportcapture
andpassive
.
void
configureFromLocation(location)
-
location
:LatLng | LatLngLiteral
The location to render place details for.
Promise
<void>
A promise that resolves once place data is loaded and rendered.LatLng
using reverse geocoding.removeEventListener(type, listener[, options])
-
type
:string
A string which specifies the type of event for which to remove an event listener. -
listener
:EventListener | EventListenerObject
The event listener of the event handler to remove from the event target. -
options
:boolean| EventListenerOptions optional
See options .
void
PlaceDetailsElementOptions interface
google.maps.places
. PlaceDetailsElementOptions
interface
Options for PlaceDetailsElement
.
Properties |
|
---|---|
size
optional
|
Type:
PlaceDetailsSize
optional
|
PlaceDetailsSize constants
google.maps.places
. PlaceDetailsSize
constants
Size variants for PlaceDetailsElement
.
Access by calling const {PlaceDetailsSize} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Constants |
|
---|---|
LARGE
|
Large variant including a large image, basic information, and contact information. |
MEDIUM
|
Medium variant including a large image and basic information. |
SMALL
|
Small variant including a small image and basic information. |
X_LARGE
|
Extra large variant including a photo collage, reviews, and comprehensive place information. |
PlaceListElement class
google.maps.places
. PlaceListElement
class
An HTML element that displays the results of a place search in a list. Use the configureFromSearchByTextRequest()
or configureFromSearchNearbyRequest()
methods to specify the request to render results for. To use the Place List Element, enable the Places UI Kit API
for your project in the Google Cloud console.
Custom element: <gmp-place-list selectable></gmp-place-list>
This class extends HTMLElement
.
This class implements PlaceListElementOptions
.
Access by calling const {PlaceListElement} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Constructor
PlaceListElement([options])
-
options
:PlaceListElementOptions optional
Properties
boolean
gmp-placeselect
event when clicked. Accessible keyboard navigation and selection is also supported.-
<gmp-place-list selectable></gmp-place-list>
Methods
addEventListener(type, listener[, options])
-
type
:string
A case-sensitive string representing the event type to listen for. -
listener
:EventListener | EventListenerObject
The object that receives a notification. This must be a function or an object with the handleEvent method -
options
:boolean| AddEventListenerOptions optional
See options . Custom events only supportcapture
andpassive
.
void
configureFromSearchByTextRequest(request)
-
request
:SearchByTextRequest
The request to render results for. Thefields
property of theSearchByTextRequest
is not required.
Promise
<void>
A promise that resolves once place data is loaded and rendered.configureFromSearchNearbyRequest(request)
-
request
:SearchNearbyRequest
The request to render results for. Thefields
property of theSearchNearbyRequest
is not required.
Promise
<void>
A promise that resolves once place data is loaded and rendered.removeEventListener(type, listener[, options])
-
type
:string
A string which specifies the type of event for which to remove an event listener. -
listener
:EventListener | EventListenerObject
The event listener of the event handler to remove from the event target. -
options
:boolean| EventListenerOptions optional
See options .
void
Events
function(event)
-
event
:Event
function(event)
-
event
:PlaceListPlaceSelectEvent
Place
object and the index of the selected place in the list.function(event)
-
event
:Event
PlaceListElementOptions interface
google.maps.places
. PlaceListElementOptions
interface
Options for PlaceListElement
.
Properties |
|
---|---|
selectable
optional
|
Type:
boolean optional
|
PlaceListPlaceSelectEvent class
google.maps.places
. PlaceListPlaceSelectEvent
class
This event is emitted by the PlaceListElement
when the user selects a place.
This class extends Event
.
Access by calling const {PlaceListPlaceSelectEvent} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Properties |
|
---|---|
index
|
Type:
number
The list index of the selected place.
|
place
|
Type:
Place
A
Place
object containing the ID, location, and viewport of the selected place. |
Autocomplete class
google.maps.places
. Autocomplete
class
A widget that provides Place predictions based on a user's text input. It attaches to an input element of type text
, and listens for text entry in that field. The list of predictions is presented as a drop-down list, and is updated as text is entered.
This class extends MVCObject
.
Access by calling const {Autocomplete} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Constructor
Autocomplete(inputField[, opts])
-
inputField
:HTMLInputElement
The<input>
text field to which theAutocomplete
should be attached. -
opts
:AutocompleteOptions optional
Options.
Autocomplete
that attaches to the specified input text field with the given options.Methods
getBounds()
LatLngBounds
|undefined
The biasing bounds.getFields()
Array
<string>|undefined
PlaceResult
.getPlace()
PlaceResult
The Place selected by the user.name
property set to the current value of the input field.setBounds(bounds)
-
bounds
:LatLngBounds | LatLngBoundsLiteral optional
The biasing bounds.
setComponentRestrictions(restrictions)
-
restrictions
:ComponentRestrictions optional
The restrictions to use.
setFields(fields)
-
fields
:Array <string> optional
PlaceResult
.setTypes(types)
-
types
:Array <string> optional
The types of predictions to be included.
Events |
|
---|---|
place_changed
|
function()
Arguments: None
This event is fired when a
PlaceResult
is made available for a Place the user has selected.If the user enters the name of a Place that was not suggested by the control and presses the Enter key, or if a Place Details request fails, the PlaceResult
contains the user input in the name
property, with no other properties defined. |
AutocompleteOptions interface
google.maps.places
. AutocompleteOptions
interface
The options that can be set on an Autocomplete
object.
Properties |
|
---|---|
bounds
optional
|
Type:
LatLngBounds
| LatLngBoundsLiteral
optional
The area in which to search for places.
|
componentRestrictions
optional
|
Type:
ComponentRestrictions
optional
The component restrictions. Component restrictions are used to restrict predictions to only those within the parent component. For example, the country.
|
fields
optional
|
Type:
Array
<string> optional
Fields to be included for the Place in the details response when the details are successfully retrieved, which will be billed for
. If
['ALL']
is passed in, all available fields will be returned and billed for (this is not recommended for production deployments). For a list of fields see PlaceResult
. Nested fields can be specified with dot-paths (for example, "geometry.location"
). The default is ['ALL']
. |
|
Type:
boolean optional
Whether to retrieve only Place IDs. The PlaceResult made available when the place_changed event is fired will only have the place_id, types and name fields, with the place_id, types and description returned by the Autocomplete service. Disabled by default.
|
strictBounds
optional
|
Type:
boolean optional
A boolean value, indicating that the Autocomplete widget should only return those places that are inside the bounds of the Autocomplete widget at the time the query is sent. Setting strictBounds to
false
(which is the default) will make the results biased towards, but not restricted to, places contained within the bounds. |
types
optional
|
Type:
Array
<string> optional
The types of predictions to be returned. For supported types, see the developer's guide
. If no types are specified, all types will be returned.
|
SearchBox class
google.maps.places
. SearchBox
class
A widget that provides query predictions based on a user's text input. It attaches to an input element of type text
, and listens for text entry in that field. The list of predictions is presented as a drop-down list, and is updated as text is entered.
This class extends MVCObject
.
Access by calling const {SearchBox} = await google.maps.importLibrary("places")
.See Libraries in the Maps JavaScript API
.
Constructor
SearchBox(inputField[, opts])
-
inputField
:HTMLInputElement
-
opts
:SearchBoxOptions optional
SearchBox
that attaches to the specified input text field with the given options.Methods
getBounds()
LatLngBounds
|undefined
getPlaces()
Array
< PlaceResult
>|undefined
places_changed
event.setBounds(bounds)
-
bounds
:LatLngBounds | LatLngBoundsLiteral optional
Events |
|
---|---|
places_changed
|
function()
Arguments: None
This event is fired when the user selects a query,
getPlaces
should be used to get new places. |
SearchBoxOptions interface
google.maps.places
. SearchBoxOptions
interface
The options that can be set on a SearchBox
object.
Properties |
|
---|---|
bounds
optional
|
Type:
LatLngBounds
| LatLngBoundsLiteral
optional
The area towards which to bias query predictions. Predictions are biased towards, but not restricted to, queries targeting these bounds.
|