fyii / geocomplete
jQuery Geocomplete widget for Yii2
Requires
- bower-asset/jquery-geocomplete: ^1.7
- yiisoft/yii2: ~2.0
This package is not auto-updated.
Last update: 2018-11-14 02:56:07 UTC
README
A geocomplete widget for Yii2 using the Geocomplete jQuery plugin.
Usage
Adding an geocomplete field based on an model attribute:
<?= $form->field($model, 'address')
->widget(\fyii\geocomplete\Widget::class) ?>
FYii-Geocomplete configure the jQuery plugin to look for the
data-geocomplete
attribute when address lookup is complete. This makes
easy to get other values from the address. For example, to get the country
code and postal code in separate fields, use the following code:
<?= $form->field($model, 'address')
->widget(\fyii\geocomplete\Widget::class) ?>
<?= $form->field($model,
'postal_code', [
'inputOptions' => [
'data-geocomplete' => 'postal_code',
],
]) ?>
<?= $form->field($model,
'country_code', [
'inputOptions' => [
'data-geocomplete' => 'country_short',
],
]) ?>
Widget Options
FYii-geocomplete widgets accept the following options:
-
mapsApiKey
- a proper Google Maps API key. The widget will not work if you do not provide a valid API key. See https://developers.google.com/maps/documentation/javascript/get-api-key for more details. -
options
- standard tag attributes -
container
- jQuery selector of HTML container that FYii-geocomplete should look fordata-geocomplete
-tagged elements. Default is parent form (obtained from Javascript). -
geocompleteOptions
- object with Geocomplete plugin options. See https://ubilabs.github.io/geocomplete/ for a complete list.