emilianotisato / nova-google-autocomplete-field

Address Autocomplete with Google Place API (full metadata available)
20 stars 17 forks source link

Extracting address_line_1 from GoogleAutocomplete #9

Closed bkilshaw closed 5 years ago

bkilshaw commented 5 years ago

Right now I have a full address form in Nova and I'm using this package to autocomplete the address. I'd like to extract address_line_1 into it's own field. I have GoogleAutocomplete::make('Address Line 1')->withValues([...]) but it's setting 'Address Line 1' to be the full address (123 Main Street, City, State Zip, Country).

Whats the best way to go about having the auto-complete field only populate with the address_line_1 and not the full postal address?

Currently:

    protected function addressFields()
    {
        return [
            GoogleAutocomplete::make('Address Line 1')->withValues([
                'locality',
                'administrative_area_level_1',
                'postal_code',
                'country',
                'latitude',
                'longitude'
            ])->countries(['CA']),

            Text::make('Address Line 2')->hideFromIndex(),
            AddressMetadata::make('City')->fromValue('locality')->hideFromIndex(),
            AddressMetadata::make('Province')->fromValue('administrative_area_level_1')->hideFromIndex(),
            AddressMetadata::make('Postal Code')->fromValue('postal_code')->hideFromIndex(),
            AddressMetadata::make('Country')->fromValue('country')->hideFromIndex(),
            AddressMetadata::make('Latitude')->fromValue('latitude')->disabled()->hideFromIndex(),
            AddressMetadata::make('Longitude')->fromValue('longitude')->disabled()->hideFromIndex(),
        ];
    }

All fields populate properly except Address Line 1 which is the full postal address, not just the street address as expected.

bkilshaw commented 5 years ago

Checked the Places API docs and realized there is no address_line_1 available so I'm extracting Street Number and Street Address individually.

midorikocak commented 4 years ago

How would you do that?