hypejunction/google_maps_autocomplete

Replaces location input with Google Maps Autocomplete

Installs: 48

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Language:JavaScript

Type:elgg-plugin

1.0.0 2017-08-29 13:43 UTC

This package is auto-updated.

Last update: 2024-11-29 04:03:46 UTC


README

Elgg 2.3

Features

  • Replaces location input with Google Maps Autocomplete

API Key

Make sure your Google API key supports:

  • 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.

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.

Accessing address parts

You can access address parts, UTC offset and lat/long of the location in your action:

$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];
...