PHP code example of osenco / filament-google-map-location-picker

1. Go to this page and download the library: Download osenco/filament-google-map-location-picker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

osenco / filament-google-map-location-picker example snippets


 composer 

php artisan vendor:publish --tag="filament-google-map-location-picker-config"




return [
    'google_map_key' => "",
];



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

use Yemenpoint\FilamentGoogleMapLocationPicker\Forms\Components\LocationPicker;

...

    public static function form(Form $form): Form
    {
        return $form->schema([
              LocationPicker::make('location')
                  ->default(json_encode(["lat" => 15.356893920277, "lng" => 44.173358011179]))//set default location
                  ->defaultZoom(12)// set zoom 
                  ->setLocationCenter([
                      'lat' => 15.356893920277,
                      'lng' => 44.173358011179,
                  ]) //set location center 
                  ->

...

    protected $fillable = [
        "location"
    ];
...

...
    function setLocationAttribute($value)
    {
        //replace lat_column_name and lng_column_name with your column names
        $this->attributes['location'] = $value;
        $_location = @json_decode($value,true);
        $this->attributes['lat_column_name'] = data_get($_location,"lat");
        $this->attributes['lng_column_name'] = data_get($_location,"lng");
    }

...