alexantr / yii2-coordinates-input
此包已被弃用且不再维护。未建议替代包。
为 Yii 2 提供地图坐标输入小部件
1.0.0
2018-02-14 15:29 UTC
Requires
- yiisoft/yii2: ~2.0.6
This package is not auto-updated.
Last update: 2020-01-24 17:13:28 UTC
README
此扩展可以渲染带有谷歌地图或雅虎地图的输入框,并允许通过点击地图快速设置坐标。
安装
通过 composer 安装扩展
composer require alexantr/yii2-coordinates-input
配置
首先在应用配置中设置 Google Maps API 密钥。此外,您还可以设置 Yandex Maps 语言 和所有地图的初始坐标。
[ 'components' => [ 'assetManager' => [ 'bundles' => [ 'alexantr\coordinates\CoordinatesAsset' => [ 'googleMapsApiKey' => 'UBcsRlxWxBjmZBvrW154fXJ4eJeeO4TFMp9pRLi', // <- put api key here 'yandexMapsLang' => 'en_US', 'initialCoordinates' => [-53.106392, 73.528748], // [latitude, longitude] 'initialZoom' => 8, // Default is 10 ], ], ], ], ]
使用
以下视图文件中的代码将渲染一个带有谷歌地图的输入框
<?= alexantr\coordinates\CoordinatesInput::widget(['name' => 'attributeName']) ?>
如果您想在 ActiveForm 中使用此输入小部件,可以这样做
<?= $form->field($model, 'attributeName')->widget(alexantr\coordinates\CoordinatesInput::className(), ['yandexMaps' => true]) ?>
所有小部件选项的默认值
<?= alexantr\coordinates\CoordinatesInput::widget([ 'name' => 'attributeName', // there is 'options' => ['class' => 'form-control coordinates-input'], 'mapOptions' => ['class' => 'coordinates-map-container'], 'initialCoordinates' => null, 'initialZoom' => null, 'yandexMaps' => false, // Set to true to use Yandex maps instead Google maps ]) ?>
initialCoordinates
的值可以是两种格式之一:[53.923172, 27.540036]
或 ['lat' => 53.923172, 'lng' => 27.540036]
。