mauricewijnia / nova-maps-address
A Laravel Nova Google Maps Field.
Installs: 34 659
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 3
Open Issues: 6
Language:JavaScript
Requires
- php: >=7.1.0
- laravel/nova: *
This package is auto-updated.
Last update: 2024-10-23 16:57:39 UTC
README
Nova Maps Address is a Nova field that allows the user to select an adress using the Google Places API and store it in a JSON column.
Table of Contents
Installation
To install the field simply run:
composer require mauricewijnia/nova-maps-address
You will need a Google Maps API key with access to the Maps, Places and Geocoding API. You can place the key in your .env
file like this:
NOVA_MAPS_ADDRESS_KEY="your_key_here"
Usage
This fields stores its data as JSON in your column, so we will have to cast our column to an array.
To add the field to your resource you can do:
use Mauricewijnia\NovaMapsAddress\MapsAddress; ... public function fields(Request $request) { return [ ... MapsAddress::make(__('Address'), 'address'), ... ]; }
And in our model:
protected $casts = [ 'address' => 'array' ]
The resulting data will have this format:
{
street_name: string,
street_number: string,
postal_code: string,
city: string,
country: string,
formatted_address: string,
latitude: float,
longitude: float
address_components: array // https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingAddressTypes
}
Options
You can change some of the settings for the map by call the respective option method:
MapsAddress::make(__('Address'), 'address') ->zoom(5) ->center(['lat' => 55.5, 'lng' => 5.5]) ->types(['address' ,'establishment']);
You can also pass parameters to Map js request and all options available for map/autocomplete/geocoder class. For example to specify a language and regions and filter the components:
MapsAddress::make(__('shop_admin.places.address'), 'address')->types([]) ->scriptUrlParams(['region' => 'jp', 'language' => 'ja']) ->autoCompleteOptions(['componentRestrictions' => ['country' => ['jp']]]) ->mapOptions(['componentRestrictions' => ['country' => ['jp']]])