Filament: Google Maps - Display Locations on Map

Filament 4
Also available in Filament 3 version

Showing markers in Google Maps using the Google Maps API.

01JF75J06A82KVR747P84RDPFP

Get the Source Code:

How it works

We have a simple shop resource to add, edit, and delete shops.

Google Maps API key is set in the .env as GOOGLE_MAPS_API_KEY.

This env is set in the config/services.php.

config/services.php:

'google' => [
'maps' => [
'key' => env('GOOGLE_MAPS_API_KEY'),
],
],

To show a map, we use a custom page. In the mount() method, we get all the shops, cast them to an array, and assign them to a $shops property.

app/Filament/Pages/Map.php:

use App\Models\Shop;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
 
class Map extends Page
{
protected static string | \BackedEnum | null $navigationIcon = Heroicon::OutlinedMapPin;
 
protected string $view = 'filament.pages.map';
 
public array $shops = [];
 
public function mount(): void
{
$this->shops = Shop::all(['name', 'lat', 'lng'])->toArray();
}
}
The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.
Get the Source Code: All 152 Premium Examples for $99