yii2-select-google-map-location

Yii2 widget to select location at map and choose map coordinates

  • 所有者: kalyabin/yii2-select-google-map-location
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

yii2-select-map-location

Yii2 widget to select location at map and choose map coordinates

This extension adds functionality to select the location on the Google map. The extension indicates the model and attributes, which stores the address, latitude and longitude.

When choosing a location map of switches and sets the marker to the selected location. The attributes recorded address and coordinates of the selected location.

Latest Stable Version
Total Downloads
Monthly Downloads
Latest Unstable Version
License

Install

Run at your console:

php composer.phar require "kalyabin/yii2-select-google-map-location" "*"

Register Google API

First, register your Google API key as described: Google API Documentation

After this, enable at Google console:

  • Google Map JavaScript API (remember API key)
  • Google Places API Web Service

Usage

Declare model class which will save geographic coordinates:

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

Render widget:

$model = new SearchLocation();
$form = \yii\widgets\ActiveForm::begin();
...
$form->field($model, 'address')->widget(\kalyabin\maplocation\SelectMapLocationWidget::className(), [
    'attributeLatitude' => 'latitude',
    'attributeLongitude' => 'longitude',
    'googleMapApiKey' => '<YOUR_REGISTERED_GOOGLE_MAP_API>',
]);
...
\yii\widgets\ActiveForm::end();

To use movable marker on the map describe draggable option:

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

To use custom field template use placeholder {map} for ActiveField:

$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(\kalyabin\maplocation\SelectMapLocationWidget::className(), [
    'attributeLatitude' => 'latitude',
    'attributeLongitude' => 'longitude',
    'googleMapApiKey' => '<YOUR_REGISTERED_GOOGLE_MAP_API>',
]);
...
\yii\widgets\ActiveForm::end();

主要指標

概覽
名稱與所有者kalyabin/yii2-select-google-map-location
主編程語言JavaScript
編程語言PHP (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2015-06-23 20:46:01
推送於2021-09-03 12:03:05
最后一次提交2021-09-03 15:03:05
發布數8
最新版本名稱1.1.4 (發布於 )
第一版名稱1.0.0 (發布於 )
用户参与
星數28
關注者數2
派生數13
提交數62
已啟用問題?
問題數0
打開的問題數0
拉請求數7
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?