2017 © Pedro Peláez
 

yii2-extension yii2-gmap-markers

GoogleMaps Widget displays a set of user addresses as markers on the map.

image

loveorigami/yii2-gmap-markers

GoogleMaps Widget displays a set of user addresses as markers on the map.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 19 % Grown

The README.md

Google Maps Widgets for Yii2

GoogleMaps Widget displays a set of user addresses as markers on the map., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require loveorigami/yii2-gmap "*"

or add, (*4)

"loveorigami/yii2-gmap": "*"

to the require section of your composer.json., (*5)

Configuration

To configure the Google Maps key or other options like language, version, library, or map options:, (*6)

echo lo\widgets\gmap\MarkersWidget::widget([
    'googleMapsUrlOptions' => [
        'key' => 'this_is_my_key',
        'language' => 'id',
        'version' => '3.1.18',
    ],
    'googleMapsOptions' => [
        'mapTypeId' => 'roadmap',
        'tilt' => 45,
        'zoom' => 5,
    ],
]);

OR via yii params configuration. For example:, (*7)

'params' => [
    'googleMapsUrlOptions' => [
        'key' => 'this_is_my_key',
        'language' => 'id',
        'version' => '3.1.18',
     ],
    'googleMapsOptions' => [
        'mapTypeId' => 'roadmap',
        'tilt' => 45,
        'zoom' => 10,
    ],
],

To get key, please visit page, (*8)

Google Maps Options you can find them on the options page, (*9)

Widgets

* Markers Widget

To use GoogleMaps, you need to configure its [[locations]] property. For example:, (*10)

echo lo\widgets\gmap\MarkersWidget::widget([
        [
            'position' => [$model->lat, $model->lng],
            'open' => true,
            'content' => $model->name,
        ],
        [
            'position' => [45.143400, -5.372400],
            'content' => 'My Marker',
        ]
]);

* Select Map Location Widget

Declare model class which will save geographic coordinates:, (*11)

class SearchLocation extends \yii\base\Model
{
    ...
    public $address;
    public $longitude;
    public $latitude;
    ...
}

Render widget:, (*12)

$model = new SearchLocation();
$form = \yii\widgets\ActiveForm::begin();
...
$form->field($model, 'address')->widget(\lo\widgets\gmap\SelectMapLocationWidget::class, [
    'attributeLatitude' => 'latitude',
    'attributeLongitude' => 'longitude',
]);
...
\yii\widgets\ActiveForm::end();

To use movable marker on the map describe draggable option:, (*13)

$model = new SearchLocation();
$form = \yii\widgets\ActiveForm::begin();
...
$form->field($model, 'address')->widget(\lo\widgets\gmap\SelectMapLocationWidget::className(), [
    'attributeLatitude' => 'latitude',
    'attributeLongitude' => 'longitude',
    'draggable' => true,
]);
...
\yii\widgets\ActiveForm::end();

To use custom field template use placeholder {map} for ActiveField:, (*14)

$model = new SearchLocation();
$form = \yii\widgets\ActiveForm::begin();
...
$form->field($model, 'address', [
    'template' => '{label}<div class="custom-class"><div class="form-control">{input}</div>{map}</div>{error}',
])->widget(\lo\widgets\gmap\SelectMapLocationWidget::className(), [
    'attributeLatitude' => 'latitude',
    'attributeLongitude' => 'longitude',
]);
...
\yii\widgets\ActiveForm::end();

The Versions

03/07 2017

dev-master

9999999-dev

GoogleMaps Widget displays a set of user addresses as markers on the map.

  Sources   Download

MIT

The Requires

  • bower-asset/gmap3 ~7.2.0

 

yii2 google map marker