Skip to main content
MapPickerField ← Back to Table of Contents

Summary

Mapbox-powered address picker with geocoding search, draggable pin, and configurable stored fields. Supports both structured array output (coordinates, street, city, etc.) and formatted string output. Ideal for location selection in delivery, real estate, or event management apps.
ClassBjanczak\FilamentFlexFields\Filament\Forms\Components\MapPickerField
State type (internal)Canonical array with keys from ALL_FIELDS
Dehydrated stateSubset of fields per fields(), or formatted string per storeFormat()
FieldTypemap_picker
Playgroundmap-picker slug in Flex Fields playground
Requires a Mapbox access token in config('filament-flex-fields.mapbox.access_token') or per-field via mapboxToken().

Basic usage

Structured Location (Coordinates + Address)

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\MapPickerField;

MapPickerField::make('location')
    ->label('Office address')
    ->fields(['lat', 'lng', 'street', 'city', 'postcode', 'country', 'place_name'])
    ->requiredFields(['lat', 'lng', 'city'])
    ->streetAddressesOnly()
    ->defaultCenter([52.2297, 21.0122])
    ->defaultZoom(12);

Formatted String Output

MapPickerField::make('venue')
    ->storeFormat(MapPickerField::STORE_STRING)
    ->stringFormat('{street}, {city} ({country})')
    ->countries(['PL', 'DE']);

State & validation

Canonical internal keys

lat, lng, street, city, region, postcode, country, country_name, place_name

Stored value

storeFormatDehydrated value
structured (default)Array with only keys from fields()
stringSingle string from stringFormat() placeholders {field}

Validation rules (built-in)

BehaviourDetail
required()At least one configured field must have a value
requiredFields()Listed fields must be filled when any value present
Latitude/LongitudeAutomatically validated when present in fields()
streetAddressesOnly()Ensures a full street address is selected; area-level results are rejected

Configuration API

All methods accept Closure unless noted.
MethodTypeDefaultDescription
fields(array $fields)SetupdefaultWhich address parts to store and show
storeFormat(string $format)Setupstructuredstructured or string
stringFormat(string $format)Setup{place_name}Template for string storage
requiredFields(array $fields)Setup[]Fields required when partially filled
mapboxToken(string $token)SetupconfigOverride Mapbox access token
defaultCenter(array $center)SetupWarsaw[latitude, longitude]
defaultZoom(int $zoom)Setup12Initial map zoom 122
searchable(bool $condition)SetuptrueShow address search box
countries(array $countries)SetupnullRestrict results to ISO country codes
streetAddressesOnly(bool $cond)SetupfalseRestrict to full street addresses only
searchTypes(array $types)SetupnullLimit results to specific place types
readOnly(bool $condition)SetupfalseDisable map interaction

Real-world examples

Pickup Point (POI only)

use Bjanczak\FilamentFlexFields\Enums\MapboxSearchType;

MapPickerField::make('pickup_point')
    ->searchTypes([MapboxSearchType::Poi])
    ->fields(['place_name', 'lat', 'lng'])
    ->required();

City Selector

MapPickerField::make('city')
    ->searchTypes([MapboxSearchType::Place])
    ->fields(['city', 'country'])
    ->storeFormat('string')
    ->stringFormat('{city}, {country}');

Playground

/admin/flex-fields-playground/map-picker See Playground for setup.
ComponentWhen to use instead
AddressAutocompleteFieldAddress search without a map
CountryFieldSimple country dropdown
FlexTextInputManual address entry

CSS classes (reference)

ClassRole
fff-map-picker-fieldRoot wrapper
fff-map-pickerAlpine root container
fff-map-picker__search-wrapSearch input + dropdown container
fff-map-picker__dropdown-panelAutocomplete suggestions list
fff-map-picker__selection-errorInline error for rejected results
fff-map-picker__canvasMapbox map container
fff-map-picker__summarySelected address summary below map