An autocomplete request allows you to find place predictions based on user input.
First of all, let's build a place autocomplete request:
use Ivory\GoogleMap\Service\Place\Autocomplete\Request\PlaceAutocompleteRequest;
$request = new PlaceAutocompleteRequest('Sydney');
The place autocomplete request constructor requires the user input as first argument.
If you want to update the user input, you can use:
$request->setInput('Sydney');
The offset is the position, in the input term, of the last character that the service uses to match predictions:
$request->setOffset(3);
The location is the point around which you wish to retrieve place information:
use Ivory\GoogleMap\Base\Coordinate;
$request->setLocation(new Coordinate(48.865475, 2.321118));
The distance (in meters) within which to return place results:
$request->setRadius(200);
The types of place results to return:
$request->setTypes([AutocompleteType::GEOCODE]);
A grouping of places to which you would like to restrict your results:
use Ivory\GoogleMap\Place\AutocompleteComponentType;
$request->setComponents([
AutocompleteComponentType::POSTAL_CODE => 59800,
AutocompleteComponentType::COUNTRY => 'fr',
]);
The language code, indicating in which language the results should be returned, if possible:
$request->setLanguage('fr');