The Places Autocomplete feature attaches to a text field on your web page, and monitors that field for character entries. As text is entered, Autocomplete returns Place predictions to the application in the form of a drop-down pick list. You can use the Places Autocomplete feature to help users find a specific location, or assist them with filling out address fields in online forms.
use Ivory\GoogleMap\Place\Autocomplete;
$autocomplete = new Autocomplete();
A variable is automatically generated when creating an autocomplete but if you want to update it, you can use:
$autocomplete->setVariable('place_autocomplete');
If you want to update the default html id (places_autocomplete) used for the autocomplete input, you can use:
$autocomplete->setInputId('place_input');
Javascript within the browser is event driven, meaning that Javascript responds to interactions by generating events, and expects a program to listen to interesting events.
- Build an event
- Configure variable
- Configure instance
- Configure trigger
- Configure handle
- Append to a place autocomplete
If you want to set default input value, you can use:
$autocomplete->setValue('foo');
If you want to restrict places types, you can use:
use Ivory\GoogleMap\Place\AutocompleteType;
$autocomplete->setTypes([AutocompleteType::ESTABLISHMENT]);
If you want to restrict the autocomplete to components, you can use:
use Ivory\GoogleMap\Place\AutocompleteComponentType;
$autocomplete->setComponents([AutocompleteComponentType::COUNTRY => 'fr']);
If you want to restrict the search area, you can configure a bound:
use Ivory\GoogleMap\Base\Bound;
use Ivory\GoogleMap\Base\Coordinate;
$autocomplete->setBound(new Bound(
new Coordinate(-2.1, -3.9),
new Coordinate(2.6, 1.4)
));
Sometimes, you want to use the autocomplete & other Google Map related libraries. The library provides many
integrations but not all of them. If you need a custom library (for example drawing
), you can use:
$autocomplete->addLibrary('drawing');
If you want to configure autocomplete input attributes, you can use:
$autocomplete->setInputAttribute('class', 'my-class');
Once you have configured your autocomplete, you can render it: