Add address autocomplete and interactive maps to Adaptive Forms

Enhance the address entry experience in Adaptive Forms with real-time address suggestions and interactive map visualization. As users type an address, matching suggestions appear, allowing them to select an address and visually confirm its location on a map.

This capability is implemented using a reusable client library that enhances the existing Text Input Core Component without requiring a custom component.

Demonstration

The following demonstration illustrates how citizens can report a neighborhood issue by entering an address and confirming its location on an interactive map.

Address autocomplete and interactive map

Prerequisites

  • AEM Forms as a Cloud Service.
  • Adaptive Forms based on Core Components.
  • An existing AEM Maven project.
  • Familiarity with AEM client libraries.

Overview of the implementation

The client library integrates the following technologies:

  • Photon - Retrieves address suggestions and geographic coordinates.
  • Leaflet - Renders the interactive map and location marker.
  • OpenStreetMap - Provides map data and tiles.
  • GuideBridge API - Updates the Adaptive Forms data model with the selected address.

The JavaScript detects the configured Text Input component, retrieves address suggestions as the user types, and displays the corresponding location on a map when an address is selected.

NOTE
Photon was selected as the address lookup service for this sample implementation for demonstration purposes only. Its inclusion does not constitute an endorsement or recommendation by Adobe. Customers are free to use any address lookup service of their choice based on their business requirements, security policies, licensing terms, and service availability. The sample client library can be adapted to integrate with an alternative address lookup provider.

Download the client library

Download or clone the sample client library from the GitHub repository.

Copy the clientlib-locationpicker folder into your AEM project’s client libraries directory under the ui.apps module.

The client library contains the following files:

clientlib-locationpicker/
├── .content.xml
├── js.txt
├── css.txt
├── js/
│   └── locationpicker.js
└── css/
    └── locationpicker.css

Configure the client library

Open the locationpicker.js file and locate the configuration object.

const config = {
    countryCode: "US",
    minCharacters: 3,
    maxSuggestions: 5,
    debounceDelay: 400,
    mapZoom: 17,
    mapHeight: 300,
    showMap: true,
    selector: 'input[name="address"]',
    somExpression: "$form.address"
};

Modify the configuration properties as needed.

Property
Description
countryCode
Restricts address suggestions to the specified country using its two-letter ISO country code.
minCharacters
Minimum number of characters required to initiate an address search.
maxSuggestions
Maximum number of address suggestions requested.
debounceDelay
Delay in milliseconds before initiating an address search.
mapZoom
Map zoom level when an address is selected.
mapHeight
Height of the map in pixels.
showMap
Enables or disables map visualization.
selector
CSS selector identifying the Text Input element.
somExpression
SOM expression of the corresponding Adaptive Forms field.
NOTE
The sample implementation is configured to retrieve addresses within the United States. Change the countryCode property to restrict address suggestions to another country.

Include the client library

The sample client library uses the following category:

aemforms.locationpicker

Include this category in your Adaptive Form’s client library configuration or add it to the embed property of your project’s existing base client library.

Deploy the updated project to your AEM Forms as a Cloud Service environment using Cloud Manager.

Configure the Adaptive Form

Create an Adaptive Form based on Core Components and add a Text Input component with the following properties:

Property
Value
Title
Location of issue
Name
address
Placeholder
Start typing an address…

The sample assumes that the address field is at the root of the Adaptive Form, with a SOM expression of $form.address.

NOTE
If you use a different field name or place the field inside a named panel, update the selector and somExpression properties in the JavaScript configuration accordingly.

Test the functionality

  1. Preview the Adaptive Form.
  2. Start typing an address in the configured Text Input field.
  3. Select an address from the suggested results.
  4. Verify that the selected address populates the field and an interactive map displays the corresponding location.
  5. Select a different address and verify that the map and location marker update automatically.

Verify the Adaptive Forms data model

The client library uses the GuideBridge API to update the Adaptive Forms data model with the selected address.

To verify the field value, open the browser developer console and execute the following command:

guideBridge.resolveNode("$form.address").value

The returned value should contain the complete selected address.

Submit the form using sample data and verify that the selected address is included in the submitted data.

Production considerations

The sample uses publicly available address lookup and map services for demonstration purposes.

Before deploying this capability to production, consider the following:

  • Review the Photon usage policy.
  • Review the OpenStreetMap tile usage policy.
  • Evaluate external service availability and usage limits.
  • Review privacy and personal data handling requirements.
  • Configure the appropriate Content Security Policy directives.
  • Consider bundling Leaflet within your AEM application.
  • Verify accessibility and keyboard navigation.
IMPORTANT
Address suggestions are retrieved from an external service. Ensure that the integration complies with your organization’s security and privacy requirements before using it with customer data. Country restrictions apply to address suggestions and do not constitute postal address validation.
recommendation-more-help
experience-manager-learn-help-cloud-service