When you have requested your place autocomplete, the returned object is a PlaceAutocompleteResponse
. It wraps a
place autocomplete status and predictions.
The available status are defined by the PlaceAutocompleteStatus
constants.
$status = $response->getStatus();
A request can return many predictions. The place autocomplete response wraps an array of PlaceAutocompletePrediction
.
$predictions = $response->getPredictions();
A prediction is a place matching your request criteria. Each prediction wraps a place id, a description, types, terms and matches.
foreach ($reponse->getPredictions() as $prediction) {
// ...
}
The place id is a unique identifier that can be used with other Google APIs.
$placeId = $prediction->getPlaceId();
The description is a human-readable name for the place.
$description = $prediction->getDescription();
The result types is an array indicates the type of the place. This array contains a set of one or more tags identifying the type of feature returned in the result. For example, a geocode of "Chicago" returns "locality" which indicates that "Chicago" is a city, and also returns "political" which indicates it is a political entity.
$types = $prediction->getTypes();
The terms is an array of terms identifying each section of the returned description (a section of the description is generally terminated with a comma). Each entry in the array has a value field, containing the text of the term, and an offset field, defining the start position of this term in the description, measured in Unicode characters.
foreach ($result->getTerms() as $term) {
$value = $term->getValue();
$offset = $term->getOffset();
}
The matches is an array with offset value and length. These describe the location of the entered term in the prediction result text, so that the term can be highlighted if desired.
foreach ($result->getMatches() as $match) {
$length = $match->getLength();
$offset = $match->getOffset();
}