PlacesSearchBox
The PlacesSearchBox is used to tie in a Google Maps Places search into a text input field using the Google Maps Places SearchBox widget.
It's recommended to use the AutocompleteSearchBox over PlacesSearchBox because the AutocompleteSearchBox gives you more options to configure the search box. See the Places widgets page "Summary of classes" for more information on the differences.
PlacesSearchBox
extends Evented.
Example usage
const placesSearchBox = G.placesSearchBox('.inputSelector');
placesSearchBox.init().then(() => {
placesSearchBox.on('places_changed', () => {
const place = placesSearchBox.getPlace();
G.marker({
map: map,
position: place.geometry.location,
tooltip: place.name,
});
map.fitBounds(placesSearchBox.getPlacesBounds());
});
});
Creating the PlacesSearchBox object
G.placesSearchBox(input?: PlacesSearchBoxValue, options? PlacesSearchBoxOptions): PlacesSearchBox
There are a few ways that you can setup the PlacesSearchBox
object.
No parameters.
G.placesSearchBox(): PlacesSearchBox
const placesSearchBox = G.placesSearchBox();
Pass the options.
G.placesSearchBox(options: PlacesSearchBoxOptions): PlacesSearchBox
Parameter | Type | Required | Description |
---|---|---|---|
options | PlacesSearchBoxOptions | Yes | The options. |
const placesSearchBox = G.placesSearchBox({
input: '#inputId'
});
Pass the input selector.
G.placesSearchBox(input: HTMLInputElement | string): PlacesSearchBox
Parameter | Type | Required | Description |
---|---|---|---|
input | HTMLInputElement | string | Yes | The input selector. |
const placesSearchBox = G.placesSearchBox('#inputId');
Pass the input selector and the options.
G.placesSearchBox(input: HTMLInputElement | string, options: PlacesSearchBoxOptions): PlacesSearchBox
Parameter | Type | Required | Description |
---|---|---|---|
input | HTMLInputElement | string | Yes | The input selector. |
options | PlacesSearchBoxOptions | Yes | The options. |
const myTextField = document.querySelector('.myInput');
const placesSearchBox = G.placesSearchBox(myTextField, {bounds: myLatLngBoundsObject});
Pass an existing PlacesSearchBox object.
G.placesSearchBox(object: PlacesSearchBox): PlacesSearchBox
In this case the PlacesSearchBox
object is simply returned.
Parameter | Type | Required | Description |
---|---|---|---|
object | PlacesSearchBox | Yes | A PlacesSearchBox object. |
const placesSearchBox = G.placesSearchBox(placesSearchBoxObject);
PlacesSearchBox value type
The PlacesSearchBoxValue
can be one of the following values:
PlacesSearchBox
object- PlacesSearchBoxOptions object
- An HTMLInputElement object that is the text input to associate the search box with.
- A string CSS selector for the text input to associate the search box with. Any valid selector for
document.querySelector
can be used.