trinityrank/google-map-with-autocomplete

Nova Google Map With Autocomplete Field Package.

v1.0.0 2022-07-27 07:24 UTC

This package is auto-updated.

Last update: 2024-09-19 15:58:10 UTC


README

此字段允许您使用Google Places API在用户输入时自动完成并显示Google Map,并获取带有所有元数据(如纬度和经度)的完整真实地址。

安装

您可以通过composer将此包安装到使用Nova的Laravel应用中

composer require trinityrank/google-map-with-autocomplete

现在发布配置和本地化文件

php artisan vendor:publish --provider="Trinityrank\GoogleMapWithAutocomplete\FieldServiceProvider"

创建一个应用并启用Places API,创建凭据以获取您的API密钥 https://console.developers.google.com

将以下内容添加到您的.env文件中

GMAPS_API_KEY=############################

使用

将use声明添加到您的资源中并使用字段

use Trinityrank\GoogleMapWithAutocomplete\TRMap;
use Trinityrank\GoogleMapWithAutocomplete\TRCountry;
use Trinityrank\GoogleMapWithAutocomplete\TRState;
use Trinityrank\GoogleMapWithAutocomplete\TRCity;
use Trinityrank\GoogleMapWithAutocomplete\TRZipCode;
use Trinityrank\GoogleMapWithAutocomplete\TRAddress;

TRMap::make('Map'), // Google Map with address picker
TRCountry::make('Country'), // Country field
TRState::make('State'), // State field
TRCity::make('City'), // City field
TRZipCode::make('Zip Code'), // Zip Code Filed
TRAddress::make('Address'), // Autocomplete address field

将use声明添加到您的资源中并使用包含所有字段的面板

use Trinityrank\GoogleMapWithAutocomplete\TRLocation;

TRLocation::make('Location'), // All fileds in panel with required rule

Image of character counter

自定义字段

为起始点添加自定义纬度、经度和缩放值

TRMap::make('Map')
    ->latitude('latitude')
    ->longitude('longitude')
    ->zoom('zoom'),

隐藏纬度和经度字段

TRMap::make('Map')
    ->hideLatitude()
    ->hideLongitude(),

您可以将任何nova基本方法添加到字段(显示/隐藏、验证等)。