jfeid / nova-google-maps
A Laravel Nova field using Google Maps to provide latitude/longitude data.
Installs: 7 517
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 2
Open Issues: 0
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2025-06-17 21:11:35 UTC
README
A Laravel Nova field that uses Google Maps to update latitude/longitude model fields.
Requirements
Package supports Nova 2.x (Laravel 5.8.x), Vue 2.6.x
Installation
Install the package in to a Laravel app that uses Nova via composer:
composer require jfeid/nova-google-maps
Publish the package configuration to your Laravel config directory:
php artisan vendor:publish --provider="Jfeid\NovaGoogleMaps\FieldServiceProvider" --tag="config"
You need to type your Google Map API key in the .env
file as follows:
GMAPS_API_KEY=YOUR_API_KEY_HERE
Optionally, you can adjust the following configuration options in the .env
file:
# Default latitude value when empty GMAPS_DEFAULT_LATITUDE= # Default longitude value when empty GMAPS_DEFAULT_LONGITUDE= # Default map zoom value GMAPS_DEFAULT_ZOOM=9
Usage
Add the following to a Nova resource:
NovaGoogleMaps::make('Location')->setValue($this->location_lat, $this->location_lng)
The field requires to initialize its value using the setValue
method by passing your model's lat/lng fields as parameters.
Also the field requires to know your names of the model's lat/lng fields in order to use them in POST requests.
By default, the field will use the base attribute ('location' in this example) suffixed with _lat
and _lng
.
For example:
// POST data ... location_lat=40.2711861 location_lng=22.4755078 ...
If the default naming does not work for you, you can explicitly set the attribute names for lat/lng as follows:
NovaGoogleMaps::make('Location')->setAttributes('my_latitude', 'my_longitude')
License
The MIT License (MIT). Please see License File for more information.