dotswan / filament-map-picker

Map Picker is a Filament custom field designed to simplify the process of choosing a location on a map and obtaining its geo-coordinates.
MIT License
56 stars 13 forks source link

Map location search form #20

Closed jorelart closed 4 months ago

jorelart commented 4 months ago

Is it possible to add search form on the map? Or maybe I didn't know it already existed.

mohaphez commented 4 months ago

To add this feature, it is necessary to use external web services such as Google or OSM APIs. which is not currently in this package

But you can simply define a TextInput. And every time the user searches for a word in it, send an api like osm. And share the result with Map field


Map::make('location')
                    ->label('Location')
                    ->afterStateUpdated(function (Get $get, Set $set, string|array|null $old, ?array $state): void {
                        $set('latitude', $state['lat']);
                        $set('longitude', $state['lng']);
                    }) ......

 TextInput::make('address')
                ->columnSpanFull()
                ->hint('Search address')
                 ->afterStateUpdated(function (Get $get): void {
                    $location = geoService()->getLocationFromAddress($get('address'));
                    $set('location', ['lat' => $location['latitude'], 'lng' => $location['longitude']]);
                })
                ->live()
                ->maxLength(255),

The code above is an example. And you need to develop the geoService() by yourself and connect it to one of the available APIs like(https://nominatim.org/release-docs/latest/api/Search) and get the information.

I hope this answer is helpful. Let me know if you have any questions or problems

jorelart commented 4 months ago

@mohaphez Thank you for the advice.

the package went well as expected, till I found a little difficulty when choosing an unfamiliar location and it should be easier when I can search using keywords.

Hopefully this feature can be included later.

So should I close this issue?

mohaphez commented 4 months ago

I am glad that this package met your needs I'll definitely put the mentioned feature in the list of future features.

Thank you.