Working With Different Address Formats
When connecting an application with other external systems to write back addresses, oftentimes there will be specific address formats that are accepted. The location components provide a few different outputs of addresses that can be used throughout the journey, to either be used as a variable or written back to other external systems like Salesforce. They can also be used to auto populate form fields that require separate address fields as well. Below are some of the different address formats the are retrievable:
Latitude and Longitude
formattedAddress:
Note: To split the formattedAddress into different address components (i.e. Address line, City, State, Zip Code), the SPLIT() Airscript function can be used to break the address apart.
addressComponents:
Getting different address formats using the Place Search Input control
The Place Search Input control can provide the three different types of address formats based off of what address is searched. The maps control can get the latitude/longitude and formattedAddress of a location, but does not provide addressComponents. For information on how to use the maps control and store the location as a variable, see Working with the Users Current Location.
The place search input control, built on top of the Places API by Google, can be used to search for specific addresses, places by categories, points of interest, and more. When configured, the control will provide the latitude, longitude, formatted address, addressComponents, identifier, name, and icon.
First, add a Place Object in AirData and name it Place.
Then add a variable of the type 'Place' on the web page. Click on the '+' icon next to variables in the inspector, go to objects, and select Place. Name the variable location. Add another variable with the type 'List of Place' and name it search_results. This example will give the option to surface to location data objects.
Once the variables are added, add the Place Search Input control on the web page.
Then select the Place Search Input control, and under the General tab in the inspector, change the searchType to autocomplete.
Go to the Actions tab in the inspector, and under the 'Search Results Changed' event, add the Set Variable action and bind search_results to event.value.
Now that search_results is bound to event.value, this will provide the ability to search for an address and bind the selected address that is searched to the search_results variable. To see the output, save the application and go to App Preview and search for an address. The output will look similar to the below. This output includes the latitude/longitude, formattedAddress, and the addressComponents and can be used to pass to other systems.
Additional: If there was a requirement to get the formattedAddress and bind it to a variable, use the Set Variable action under results changed and bind the location variable to search_results[0].formattedAddress.
Lastly, to get the value of the place search input control to change to the selected address, add another Set variable action after the above action and bind place_search_inputvariable (auto bound variable for the place search input control) to the location variable.
Last updated