The Place Autocomplete service is a web service that returns place predictions in response to an HTTP request. The request specifies a textual search string and optional geographic bounds. The service can be used to provide autocomplete functionality for text-based geographic searches, by returning places such as businesses, addresses and points of interest as a user types.
The Place Autocomplete service can match on full words as well as substrings. Applications can therefore send queries as the user types, to provide on-the-fly place predictions. The returned predictions are designed to be presented to the user to aid them in selecting the desired place. You can send a Place Details request for more information about any of the places which are returned.
The Place Autocomplete API requires an http client and a serializer. The library relies respectively on Httplug which is an http client abstraction library and the Ivory Serializer which is an advanced (de)-serialization library.
To install them, read this documentation.
By default, the place autocomplete service is disabled. In order to enable the service, you need to configure it.
The http client and message factory are mandatory. They define which http client and message factory the place autocomplete service will use for issuing http requests.
First, configure the Httplug bundle.
httplug:
classes:
client: Http\Adapter\Guzzle7\Client
message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
clients:
acme:
factory: httplug.factory.guzzle7
Then, configure the Google Map bundle:
ivory_google_map:
place_autocomplete:
client: httplug.client.default
message_factory: httplug.message_factory.default
The format allows you to use json/xml format for your http request:
ivory_google_map:
place_autocomplete:
format: json
The API key allows you to bypass Google limitation according to your account plan:
ivory_google_map:
place_autocomplete:
api_key: ~
The business account allows you to use Google Premium account:
ivory_google_map:
place_autocomplete:
business_account:
client_id: ~
secret: ~
channel: ~
Once you have configured your place autocomplete service, you can fetch it from the container and use it as explained in the documentation.
use Ivory\GoogleMap\Service\Place\Autocomplete\Request\PlaceAutocompleteRequest;
$request = new PlaceAutocompleteRequest('Sydney');
$response = $this->container->get('ivory.google_map.place_autocomplete')->process($request);