Google Maps Autocomplete
, (*1)
Features
- Replaces location input with Google Maps Autocomplete
API Key
Make sure your Google API key supports:, (*2)
- Google Maps JavaScript API
- Google Places API Web Service
Notes
Autocomplete options
You can pass options to google.maps.places.Autocomplete
component using data-
attributes of the input field., (*3)
echo elgg_view_input('location', [
'name' => 'city_in_france',
'data-types' => json_encode(['(cities)']),
'data-component-restrictions' => json_encode(['country' => 'fr']),
]);
You can further filter options for each input using 'options', 'input/location'
JavaScript plugin hook., (*4)
Accessing address parts
You can access address parts, UTC offset and lat/long of the location in your action:, (*5)
$location = get_input('my_input_name');
$extended = get_input('__location');
$index = array_search($location, $extended['location']);
$street_address = $extended['street_address'][$index];
$postal_code = $extended['postal_code'][$index];
...