libaocai/laravel-admin-map-selector

laravel admin 地图选择扩展

v1.0.2 2021-02-25 11:50 UTC

This package is auto-updated.

Last update: 2024-09-26 16:55:25 UTC


README

这个扩展用于帮助你在表单中选择经纬度,用来替代Laravel-admin中内置的Form\Field\Map组件,支持的地图包括谷歌地图百度地图高德地图腾讯地图Yadex地图

此扩展用于在表单中选择经纬度,以替换Laravel-admin中内置的Form\Field\Map组件。支持的地图包括谷歌地图百度地图高德地图腾讯地图Yadex地图

安装

composer require libaocai/laravel-admin-map-selector

配置

打开 config/admin.php 文件,并将以下配置添加到扩展部分

'extensions' => [
        'latlong' => [
            // Whether to enable this extension, defaults to true
            'enable' => true,
            // Specify the default provider
            'default' => 'google',
            // According to the selected provider above, fill in the corresponding api_key
            'providers' => [
                'google' => [
                    'api_key' => '',
                ],
                'yadex' => [
                    'api_key' => '',
                ],
                'baidu' => [
                    'api_key' => 'xck5u2lga9n1bZkiaXIHtMufWXQnVhdx',
                ],
                'tencent' => [
                    'api_key' => 'VVYBZ-HRJCX-NOJ4Z-ZO3PU-ZZA2J-QPBBT',
                ],
                'amap' => [
                    'api_key' => '3693fe745aea0df8852739dac08a22fb',
                ],
            ]
        ]
]

用法

假设你的表中有两个字段 latitudelongitude 分别表示纬度和经度,那么在表单中使用以下代码

$form->latlong('latitude', 'longitude', 'Position');

// Set the map height
$form->latlong('latitude', 'longitude', 'Position')->height(500);

// Set the map zoom
$form->latlong('latitude', 'longitude', 'Position')->zoom(16);

// Set default position
$form->latlong('latitude', 'longitude', 'Position')->default(['latitude' => 90, 'longitude' => 90]);

在展示页面中使用

$show->field('Position')->latlong('lat_column', 'long_column', $height = 400, $zoom = 16);