cheesegrits / filament-google-maps

Google Maps package for Filament PHP
235 stars 65 forks source link

City (Locality): %L - Not appearing in reverse geocode results #19

Open webbedfeet-stu opened 1 year ago

webbedfeet-stu commented 1 year ago

When doing reverse geolocation, the city isn't appearing in the debug results:

{
    "%n": "4",
    "%S": "The Friary",
    "%A2": "Wiltshire",
    "%a2": "Wiltshire",
    "%A1": "England",
    "%a1": "England",
    "%C": "United Kingdom",
    "%c": "GB",
    "%z": "SP1 2HU"
}

However, when doing the same reverse geocode in the artisan command, it's appearing in the results:

stu@computer:~/code/project$ lando artisan filament-google-maps:reverse-geocode

 Latitude (e.g. `34.38461`):
 > 51.065291251694404

 Longitude (e.g. `-83.185639`):
 > -1.7925198533398445

+--------+----------------+
| Symbol | Result         |
+--------+----------------+
| %n     | 4              |
| %S     | The Friary     |
| %L     | Salisbury      |
| %D     |                |
| %z     | SP1 2HU        |
| %A1    | England        |
| %A2    | Wiltshire      |
| %A3    |                |
| %A4    |                |
| %A5    |                |
| %a1    | England        |
| %a2    | Wiltshire      |
| %a3    |                |
| %a4    |                |
| %a5    |                |
| %C     | United Kingdom |
| %c     | GB             |
| %T     |                |
+--------+----------------+

Here is the form schema I'm using:

public static function form(Form $form): Form
    {
        return $form->schema([
            Group::make()->schema([
                Card::make()->schema([
                    TextInput::make('name')->required(),
                    TextInput::make('url')->label('URL'),
                    TextInput::make('formatted_address')
                        ->label('Lookup address'),
                    TextInput::make('street')->required(),
                    TextInput::make('city')->required(),
                    TextInput::make('county')->required(),
                    TextInput::make('country')->required(),
                    TextInput::make('postcode')->required(),
                    TextInput::make('latitude')
                        // ->hidden()
                        ->disabled(),
                    TextInput::make('longitude')
                        // ->hidden()
                        ->disabled(),
                ]),
            ]),
            Group::make()->schema([
                Card::make()->schema([
                    ...Timestamps::make(),
                ]),
            ]),
            Group::make()->columnSpan(2)->schema([
                Map::make('location')
                    ->autocomplete('formatted_address')
                    ->defaultZoom(12)
                    ->debug()
                    ->autocompleteReverse()
                    ->defaultLocation([51.500765, -0.124615])
                    ->afterStateUpdated(function ($state, callable $get, callable $set) {
                        $set('latitude', $state['lat']);
                        $set('longitude', $state['lng']);
                    })
                    ->reverseGeocode([
                        'street' => '%n %S',
                        'city' => '%L',
                        'county' => '%A2',
                        'country' => '%C',
                        'postcode' => '%z',
                    ]),
            ]),
        ]);
    }

Not sure if it's something I've done wrong in the schema config or an actual issue but any ideas are appreciated.

webbedfeet-stu commented 1 year ago

Managed to figure out the issue, I've submitted a PR (#21) which fixes it.

cheesegrits commented 1 year ago

@webbedfeet-stu

Hey, I'll test that PR out later today, and merge it if it passes testing.