Unable to access FormattedAddressLine of Address Object

Question:
I have an Address Input Field on my page. I can access most elements (city, streetAddress.number, etc) except the “streetAddress.formattedAddressLine” field and “subdivisions” which don’t exist according to Studio but do when I console.log(address). How do I access these fields?

Product:
Wix Studio Editor

What are you trying to achieve:
I’d like users to be able to use the Address auto-complete field, but this seems to have limitations such as no Apartment number and no ability for the user to update information if the address field autocomplete got the address wrong. I was thinking using OnChange of the Address input field to copy each element to the related input fields on my page. Users could also edit the other address fields as needed.

What have you already tried:
Tried accessing those fields in my code:

$w('#street').value = address.value.formattedAddressLine;

the right side formattedAddressLine gets an error in Studio:
‘Property formattedAddressLine’ does not exist on type ‘address’.

Additional information:
Here’s the output of console.log(address):

value: Object
   city: "Boardman"
   country: "US"
   formatted: "123 Willow Fork Dr SW, Boardman, OR 97818, USA"
  location:
     latitude: 45.829246
     longitude: -119.7019148
  postalCode: "97818"
  streetAddress:
    apt: ""
    formattedAddressLine: "123 Willow Fork Dr SW"
    name: "Willow Fork Drive Southwest"
    number: "123"
  subdivision: "OR"
  subdivisions: Array(4)
    0: {code: 'OR', name: 'Oregon', type: 'ADMINISTRATIVE_AREA_LEVEL_1'}
    1: {code: 'Morrow County', name: 'Morrow County', type: 'ADMINISTRATIVE_AREA_LEVEL_2'}
    2: {code: 'Boardman', name: 'Boardman', type: 'ADMINISTRATIVE_AREA_LEVEL_3'}
    3: {code: 'US', name: 'United States', type: 'COUNTRY'}
    length: 4

I was not accessing the field correctly. :person_facepalming: It should be:

$w('#street').value = address.value.streetAddress.formattedAddressLine;

On to figuring out Apartments (and PO Boxes and…?).

1 Like