Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues Returning Certain Addresses #98

Open
mtwallace opened this issue Oct 11, 2021 · 1 comment
Open

Issues Returning Certain Addresses #98

mtwallace opened this issue Oct 11, 2021 · 1 comment

Comments

@mtwallace
Copy link

mtwallace commented Oct 11, 2021

So we've had the autocomplete live on our site for several weeks and our QA person found some issues that I can't quite put a finger on.

Here's the options in my component:

options = {
      componentRestrictions: { country: ["US"] },
      fields: ["address_components"],
      types: ["address"]
  }

Here's my handleAddressChange method:

handleAddressChange = (address: Address) => {
    const streetNumber = this.getComponentByType(address, "street_number");
    const streetNumberSN = streetNumber ? streetNumber.short_name : '';
    const street = this.getComponentByType(address, "route");
    const streetSN = street ? street.short_name : '';
    const city = this.getComponentByType(address, "locality");
    const citySN = city ? city.short_name : '';
    const state = this.getComponentByType(address, "administrative_area_level_1");
    const stateSN = state ? state.short_name : '';
    const zip = this.getComponentByType(address, "postal_code");
    const zipSN = zip ? zip.short_name : '';

    if (streetNumberSN) {
        this.showValidation = false;
        this.AddressForm.controls['location'].disable();
        this.sessionLead.Address = streetNumberSN ? streetNumberSN + " " + streetSN : streetSN;
        this.sessionLead.City = citySN;
        this.sessionLead.State = stateSN;
        this.sessionLead.ZipCode = zipSN;
    }
}

getComponentByType:

public getComponentByType(address: Address, type: string): AddressComponent {
    if (!type)
        return null;

    if (!address || !address.address_components || address.address_components.length == 0)
        return null;

    type = type.toLowerCase();

    for (let comp of address.address_components) {
        if (!comp.types || comp.types.length == 0)
            continue;

        if (comp.types.findIndex(x => x.toLowerCase() == type) > -1)
            return comp;
    }

    return null;
}

This first address, which is outside of the US, causes the page to become unresponsive and crash:
"1519 Prindsen Gade Charlotte Amalie, St Thomas"

This second address doesn't return a street number despite entering one and picking corresponding option which includes the street number:
"21627 Hardingrove Road, Milesville, SD, 57553"

Is there anything that can be done to fix these things? Is this on Google or is it me? Thanks!

@mtwallace
Copy link
Author

First bug was because of my validation regex but still not able to get the street number for the second address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant