cheesegrits / filament-google-maps

Google Maps package for Filament PHP
212 stars 60 forks source link

Geocomplete, lan, lon? #71

Open robertpotkowa opened 6 months ago

robertpotkowa commented 6 months ago

Is it possible to get lan, lon out of submitting the geocomplete field, instead the searched address? I use the field as a standalone search inside a livewire component.

Pronesti commented 5 months ago

This is doing both reverse Geocode and setting lat and lng inputs on my form.

Geocomplete::make('address_1')
    ->reactive()
    ->types(['premise'])
    ->countries(['us'])
     ->reverseGeocode([
       'city'   => '%L',
        'zip_code'    => '%z',
        'state'  => '%A1',
        'address_1' => '%n %S',
    ])
    ->updateLatLng(),
Alex92zz commented 1 month ago

are you using php filament v2 or v3? I am using v3 and I have the same problem, doesn't update my "lat" and "lng" fields.

Strangely enough mine it works only if I click on the address multiple times.

For example if I drag the pin on the map for the first time or I search for an address it will update the "lng" and "lat" from the Map::make('location) using:

->afterStateUpdated(function ($state, callable $get, callable $set) {
                                        // This method is called every time the map marker is moved
                                        Log::info('afterStateUpdated from map: ' . json_encode($state));
                                        $set('lng', $state['lng']);
                                        $set('lat', $state['lat']);
                                    })

After this the ->afterStateUpdated() will not be called again, even if I drag and drop in another location.

But if I drag and drop in another location, the address will change in the Geocomplete::make('site_address') dropdown, I select the address and the "lng" and "lat" are not being changed, I click again on the input box, dropdown appears, I select again on the address showing up from "powered by Google", nothing happens again, when I do it 3th time somehow it triggers this ->updateLatLng() and it updates the "lat" and "lng".

And after it updates the "lat" and "lng" if I click again on the input box for the full_address the dropdown from the "powered by Google" doesn't appear anymore.


Another way to update the "lat" and "lng" on the first click is if I click on the ->geolocate() button. I don't need to click on this button multiple times to update the "lat" and "lng". I only click once and it works properly, I think something was implemented correctly for this function but not for ->updateLatLng().