F
Filament3mo ago
MZX

Map Picker by DotSwan not fetching coordinates

This is the code, created the migrations for latitude and longitude as stated in the docs.
Map::make('location')
->label('Location')
->columnSpanFull()
->defaultLocation(latitude: 40.4168, longitude: -3.7038)
->afterStateUpdated(function (Set $set, ?array $state): void {
$set('latitude', $state['lat']);
$set('longitude', $state['lng']);
})
->afterStateHydrated(function ($state, $record, Set $set): void {
if ($record && $record->latitude && $record->longitude) {
// Set the map location to the saved latitude and longitude when editing
$set('location', ['lat' => $record->latitude, 'lng' => $record->longitude]);
}
})
->extraStyles([
'min-height: 150vh',
'border-radius: 50px'
])
->showMarker()
->markerColor("#22c55eff")
->zoom(15),
TextInput::make('latitude')
->hiddenLabel()
->hidden()
->dehydrated(), // Ensures it will be saved when the form is submitted

TextInput::make('longitude')
->hiddenLabel()
->hidden()
->dehydrated(), // Ensures it will be saved when the form is submitted
Map::make('location')
->label('Location')
->columnSpanFull()
->defaultLocation(latitude: 40.4168, longitude: -3.7038)
->afterStateUpdated(function (Set $set, ?array $state): void {
$set('latitude', $state['lat']);
$set('longitude', $state['lng']);
})
->afterStateHydrated(function ($state, $record, Set $set): void {
if ($record && $record->latitude && $record->longitude) {
// Set the map location to the saved latitude and longitude when editing
$set('location', ['lat' => $record->latitude, 'lng' => $record->longitude]);
}
})
->extraStyles([
'min-height: 150vh',
'border-radius: 50px'
])
->showMarker()
->markerColor("#22c55eff")
->zoom(15),
TextInput::make('latitude')
->hiddenLabel()
->hidden()
->dehydrated(), // Ensures it will be saved when the form is submitted

TextInput::make('longitude')
->hiddenLabel()
->hidden()
->dehydrated(), // Ensures it will be saved when the form is submitted
The latitude and longitude are empty on creating a new record.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server