lara-zeus/filament-locationpickr-field 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lara-zeus/filament-locationpickr-field

最新稳定版本:v4.0.0

Composer 安装命令:

composer require lara-zeus/filament-locationpickr-field

包简介

Location picker field for Filament Php using Google Maps

README 文档

README

This package provides just a simplified location picker field within Filament using Google Maps based on the excellent work of Hugh Messenger.

Installation

You can install the package into a Laravel app that uses Filament via composer::

composer require lara-zeus/filament-locationpickr-field

Filament V3 & V2 - you can use https://github.com/arbermustafa/filament-locationpickr-field repository.

You can publish the config file with:

php artisan vendor:publish --tag=filament-locationpickr-field-config

The config file contains default global customization options for map rendering, like: api key, default location, etc.

Optionally, you can publish the view using:

php artisan vendor:publish --tag=filament-locationpickr-field-views

Setting your Google Maps API Key

All use of the Google Maps API requires an API key. If you don't have one, refer to Google's documentation.

Once you have a key, either add it to your .env file as:

GMAP_API=your_map_api_key_here

... or publish and edit the filament-locationpickr-field.php config file.

Preparing the models

Add a location column to any model migration schema used for map data

...

Schema::table('table_name', function (Blueprint $table) {
    $table->json('location')->nullable();
});

...

and add the column to the model fillable array

...

protected $fillable = [
    ...
    'location',
];

If you have separate columns for lat and lng you can use a computed property on any model being used for map data and use a mutator which converts between separate lat and lng fields on your table, and a Google Point style array of 'lat' and 'lng' keys.

...

protected $appends = [
    ...
    'location',
];

...

public function location(): Attribute
{
    return Attribute::make(
        get: fn ($value, $attributes) => json_encode([
            'lat' => (float) $attributes['lat'],
            'lng' => (float) $attributes['lng'],
        ]),
        set: fn ($value) => [
            'lat' => $value['lat'],
            'lng' => $value['lng'],
        ],
    );
}

...

Usage

Form field

The form field can be used with no options, by simply adding this to your Filament Form schema:

use LaraZeus\FilamentLocationPickrField\Forms\Components\LocationPickr;
...

    ->schema([
        ...
        LocationPickr::make('location'),
        ....
    ]);
...

The name used in the make() function must be the one you set up as your model's column/computed location property.

Full options

The full set of options is as follows. All option methods support closures, as well as direct values.

use LaraZeus\FilamentLocationPickrField\Forms\Components\LocationPickr;
...

    ->schema([
        ...
        LocationPickr::make('location')
            ->mapControls([
                'mapTypeControl'    => true,
                'scaleControl'      => true,
                'streetViewControl' => true,
                'rotateControl'     => true,
                'fullscreenControl' => true,
                'zoomControl'       => false,
            ])
            ->defaultZoom(5)
            ->draggable()
            ->clickable()
            ->height('40vh')
            ->defaultLocation([41.32836109345274, 19.818383186960773])
            ->myLocationButtonLabel('My location'),
        ....
    ]);
...

Infolist entry

The infolist entry can be used with no options, by simply adding this to your Filament Infolist schema:

use LaraZeus\FilamentLocationPickrField\Infolists\Components\LocationPickr;
...

    ->schema([
        ...
        LocationPickr::make('location'),
        ....
    ]);
...

The name used in the make() function must be the one you set up as your model's column/computed location property. The components accepts options like defaultZoom, defaultLocation and height.

Example usage in simple resource

Locationpickr field in modal

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

If you want to contribute to this package, you may want to test it in a real Filament project:

  • Fork this repository to your Github account.
  • Create a Filament app locally.
  • Clone your fork in your Filament app root directoy.
  • In the /filament-locationpickr-field directory, create a branch for your fix/improvement, e.g. fix/pickr-field.

Install the package in your app's composer.json:

"require": {
    "lara-zeus/filament-locationpickr-field": "dev-fix/pickr-field as dev-main",
},
"repositories": [
    {
        "type": "path",
        "url": "./filament-locationpickr-field"
    }
]

Now run composer update.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 101
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-12