PHPackages                             sdfim/filament-google-maps-fork - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sdfim/filament-google-maps-fork

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sdfim/filament-google-maps-fork
===============================

A Google Maps package for Filament PHP with field, column and widget

v3.0.18(1y ago)02MITPHPPHP ^8.0

Since Apr 2Pushed 1y agoCompare

[ Source](https://github.com/sdfim/filament-google-maps)[ Packagist](https://packagist.org/packages/sdfim/filament-google-maps-fork)[ Docs](https://github.com/sdfim/filament-google-maps)[ RSS](/packages/sdfim-filament-google-maps-fork/feed)WikiDiscussions v3 Synced 1mo ago

READMEChangelog (1)Dependencies (17)Versions (2)Used By (0)

Filament Google Maps
====================

[](#filament-google-maps)

This package provides a comprehensive set of tools for using Google Maps within the [Filament PHP](https://filamentphp.com) ecosystem (an application builder for [Laravel](https://laravel.com)), either as part of an admin panel, or in standalone front end forms, tables and dashboards.

About The Project
-----------------

[](#about-the-project)

### Filament v3 release

[](#filament-v3-release)

This is the v3 branch, compatible with the recent Filament v3 release. At some point soon we will replace the main branch (currently the Filament v2 compatible branch) with this v3 branch, and move Filament v2 support to a v2 branch.

Please report any you find either on the [GitHub Issues](https://github.com/cheesegrits/filament-google-maps/issues) page, or find me (@cheesegrits) on the [Filament Discord server](https://filamentphp.com/discord).

### API Usage

[](#api-usage)

**IMPORTANT NOTE** - some features of this package could potentially drive up your API bill. If you have large tables that you display static maps on, and you clear your cache frequently. Or if you allow public access to forms that use geocoding, and get hit by bots.

We **strongly** suggest you set [usage quotas in your Google Console](https://console.cloud.google.com/projectselector2/google/maps-apis/quotas). We are not liable if you get a surprise bill!

### TL/DR

[](#tldr)

If you just can't handle reading documentation and want to dive right in ...

```
composer require cheesegrits/filament-google-maps "^3.0"
```

... then follow these instructions to add a computed attribute to any model(s) that will use these components (which should already have separate lat and lng fields, even if they are empty, see the Batch Commands section) ...

```
php artisan filament-google-maps:model-code
```

... then start using the components, like ...

```
use Cheesegrits\FilamentGoogleMaps\Fields\Map
...
->schema[
    ...
    // must use the computed attribute name you used on your model
    // which must NOT exist on the table itself
    Map::make('location'),
    ...
]
```

Components
----------

[](#components)

### Map Field

[](#map-field)

The **Map** field displays (unsurprisingly) a Google map, with a comprehensive set of configuration options. It supports coordinate updating both ways between map and form, forward and revese geocompletion, reverse geocoding and KML layers.

[![Map Field](images/form-map.png)](images/form-map.png)

### Geocomplete Field

[](#geocomplete-field)

The **Geocomplete** field turns a text field on your form into a Google geocomplete field, with optional reverse geocoding of address components.

[![Geocomplete Field](images/form-geocode.png)](images/form-geocode.png)

### Infolist Field

[](#infolist-field)

The **MapEntry** Infolist field displays a (read only) map showing a single pin. This is currently WIP, features and functionality (like KML layers, GeoJSON drawings, etc) to be added soon.

[![Infolist Field](images/infolist.png)](images/infolist.png)

### Map Widget

[](#map-widget)

The **MapWidget** displays a filterable set of locations from a model, with optional clustering, templatable labels, customizable icons, etc.

[![Map Widget](images/widget-maps.png)](images/widget-maps.png)

### Map Table Widget

[](#map-table-widget)

The **MapTableWidget** displays a map widget, along with a Filament Table, and reacts to all filtering and searching on the table.

[![Map Table Widget](images/widget-table-map.png)](images/widget-table-map.png)

### Map Column

[](#map-column)

The **MapColumn** displays a customizable static map image, with the images cached locally to reduce API overhead.

[![Map Column](images/table-map.png)](images/table-map.png)

### Static Map Action

[](#static-map-action)

The **StaticMapAction** is a bulk action that lets you select any number of table rows, and generate a downloadable static map showing those locations.

[![Static Map Action](images/static-map-action.png)](images/static-map-action.png)

### Radius Filter

[](#radius-filter)

The **RadiusFilter** provides radius filtering against a geocomplete address, in kilometers or miles.

[![Radius Filter](images/radius.png)](images/radius.png)

### Batch Commands

[](#batch-commands)

The **Artisan commands** allow you to do batch processing on your location tables, either geocoding a combination of address fields into lat lng, or reverse geocoding lat and lng to address fields.

[![Filament Google Maps Artisan command](images/artisan.png)](images/artisan.png)

([back to top](#readme-top))

Getting Started
---------------

[](#getting-started)

### Prerequisites

[](#prerequisites)

This package is built on Filament V2, and Laravel 9. It may run on earlier versions of Laravel, but has not been tested.

### Installation

[](#installation)

You can install this project via composer:

```
composer install cheesegrits/filament-google-maps
```

### Assets

[](#assets)

This package handles asynchronous loading of JS and CSS assets, in both the Filament Admin Panel and standalone pages, with no need to publish anything or modify your project.

### Preparing Models

[](#preparing-models)

To simplify working with coordinate data, we require a computed property on any model being used for map data, which converts between separate lat and lng fields on your table, and a Google Point style array of 'lat' and 'lng' keys.

To prepare your model, use the Artisan command:

```
php artisan filament-google-maps:model-code
```

... which will prompt you for:

- model: your model class, such as Places, or Dealerships/Dealership
- lat: your latitude attribute (existing table field)
- lng: your longitude attribute (existing table field)
- location: the computed property name, which **should not exist** on your table

The 'location' computed attribute is what you will use when you make() your map fields and columns. If you have no religious preference and it doesn't already exist on your table, just use 'location'.

It will then spit out the code for you to copy and paste to your model class.

**NOTE** - this script also gives you modified $fillable and $appends arrays if required, which will merge any existing content of these arrays, make sure you replace the existing ones if you already have them.

### Setting your Google Maps API Key

[](#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](https://developers.google.com/maps/documentation/javascript/get-api-key).

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

```
GOOGLE_MAPS_API_KEY=your_map_key_here
```

... or publish and edit the filament-google-maps.php config file. We recommend using an environment variable. Note that we deliberately use the same key name used by most Google related Laravel packages, just to make life easier. However, if need to use a different key for this package, you may do so - refer to the config file in the next section.

### Publish the configuration

[](#publish-the-configuration)

You may optionally publish the package configuration. The configuration comes with a set of sane defaults, so we suggest not publishing unless you actually need to change something ... and even then, best to do it with .env variables.

```
php artisan vendor:publish --tag="filament-google-maps-config"
```

... which can then be found in ./config/filament-google-maps.php

Of particular note are the config settings for your API Keys and the cache store. By default, we will cache all API responses for 30 days, using your default cache driver. For most normal usage this is sufficient, but if you expect heavy usage, we suggest setting up a dedicated Redis store in your cache.php config, and specify this with the FILAMENT\_GOOGLE\_MAPS\_CACHE\_STORE environment variable.

  (*click to expand*)```
