The location package ships with a google maps field that let's you benefit from the extensive places api, to search for location's or pick one from the map.
Bladesmith was created by Lennart Carstens-Behrens under the Sponsorware license.
Sponsor litstack to get access to this package.
Add the Litstack repository to your application's composer.json file:
"repositories": [
{
"type": "composer",
"url": "https://store.litstack.io"
}
],
composer require litstack/location
Now you need to get an api key to make use of google maps in your litstack project.
The api key must now be added to your config under
lit.location.google_api_key
:
'location' => [
'google_api_key' => env('GOOGLE_MAPS_API_KEY'),
],
The maps field let's the user pick location by searching for it or clicking somewhere on the map.
The map field requires 2 parameters, the first one is the name of the latitude attribute, the second parameter is the longitute attribute name.
$form->map('lat', 'lng');
The maps field let's you store additional information about places to your
Model. This can be achieved by passing an array as a third parameter to the maps
field, containting the desired attributes and the database column in which the
attribute should be stored. In the following example the formatted_address
would be stored in the street
column.
$form->map('lat', 'lng', [
'formatted_address' => 'street',
]);
The following attributes are available:
Method | Description |
---|---|
formatted_address |
The formatted address name. |
street_number |
The location's street number. |
street_name |
The location's street name. |
state |
The locaiton's state. |
city |
The location's city name. |
country |
The location's country. |
postal_code |
The location's postal code. |