Map

screenshot

1Map::make()
2 ->name('location')
3 ->openMap()
1<x-twill::map
2 name="location"
3 label="Location"
4 :show-map="true"
5/>
1@formField('map', [
2 'name' => 'location',
3 'label' => 'Location',
4 'showMap' => true,
5])
Option Description Type/values Default value
name Name of the field string
label Label of the field string
showMap Adds a button to toggle the map visibility boolean true
openMap Used with showMap, initialize the field with the map open boolean false
saveExtendedData Enables saving Bounding Box Coordinates and Location types boolean false

This field requires that you provide a GOOGLE_MAPS_API_KEY variable in your .env file.

A migration to save a map field would be:

1Schema::table('posts', function (Blueprint $table) {
2 ...
3 $table->json('location')->nullable();
4 ...
5});

The field used should also be casted as an array in your model:

1public $casts = [
2 'location' => 'array',
3];

When used in a block, no migration is needed.

Example of data stored in the Database:

Default data:

1{
2 "latlng": "48.85661400000001|2.3522219",
3 "address": "Paris, France"
4}

Extended data:

1{
2 "latlng": "51.1808302|-2.256022799999999",
3 "address": "Warminster BA12 7LG, United Kingdom",
4 "types": [
5 "point_of_interest",
6 "establishment"
7 ],
8 "boundingBox": {
9 "east": -2.25289275,
10 "west": -2.257066149999999,
11 "north": 51.18158853029149,
12 "south": 51.17889056970849
13 }
14}