Skip to main content
By the end of this guide, you will have an address form that suggests addresses as the user types, fills structured fields from the chosen suggestion, lets the user correct them, and checks a hand-typed address before accepting it.

Complete example

The JavaScript tab is the whole address form in one HTML page, and the other tabs make the same autocomplete and geocode calls in a native app.

Prerequisites

  • A publishable key. See Choose the right API key. Never put a secret key in client code.
  • Web: The examples use radar-sdk-js 5.3.0 and @radarlabs/plugin-autocomplete 1.2.0, which requires radar-sdk-js 5.3.0 or later. Geocoding and validation are part of the core SDK.
  • No location permission, unless you reverse geocode the user’s current position.

Formatted address, geocoded coordinate, and validated address

A Radar address result can carry three kinds of information. Don’t treat one as another.

Add the autocomplete component

Load the stylesheet, the core SDK, and the autocomplete plugin, in that order, as the JavaScript tab does. With npm, install the packages:
Then import @radarlabs/plugin-autocomplete/dist/radar-autocomplete.css, call Radar.registerPlugin(createAutocompletePlugin()), and initialize with your publishable key. Radar.ui.autocomplete() renders a search input and a suggestions list into container, an element ID or element, and handles keyboard navigation and screen reader announcements. If you pass an existing input element, it attaches the list to that input. In a single-page app, create the component once per mount and call its remove() method on unmount.

Fill structured fields from the selection

onSelection receives one address object. The example copies number and street (or addressLabel), unit, city, stateCode, postalCode, and countryCode into editable fields and keeps latitude and longitude with them. Every field except the coordinate can be absent, so read them defensively. Store the structured fields and the coordinate, not only formattedAddress. For every field, see Address object.

Check a typed address on submit

Autocomplete suggests an address. It doesn’t decide which address is right. Keep the fields editable after a selection so the user can add a unit, fix a postal code, or enter an address Radar doesn’t know, such as a new building. In the example, adding a unit keeps the selection, and editing any other field clears it. When the address was typed or edited by hand, the example sends the combined fields to Radar.forwardGeocode() and branches on the response: Whether your product blocks submission when nothing matches is your decision. Enforce it on your backend as well, because anything sent from a browser can be changed by the user. This check confirms that the address resolves to a location. It isn’t address validation.

Tune the component

The component also accepts lang, postalCode, mailable, placeholder, width, maxHeight, disabled, showMarkers, markerColor, hideResultsOnBlur, idPrefix, ariaLabel, onResults, and onRequest. To keep your own input and suggestions list, call the autocomplete operation through a Radar.AutocompleteSession, and apply the same minimum input length and debounce yourself. See Web SDK.

Use the other operations

Each operation accepts a publishable key.

Forward geocode

Radar.forwardGeocode({ query }) converts a complete address to a coordinate. Use autocomplete for partial input instead of calling it on every keystroke. Check confidence before you rely on the coordinate for anything precise, such as a delivery pin. See Forward geocode.

Reverse geocode

Radar.reverseGeocode({ latitude, longitude }) converts a coordinate to the nearest address. If you omit the coordinate, the SDK requests the browser’s location first, which shows a permission prompt. See Reverse geocode.

Validate an address

Address validation is available on the Enterprise plan, for United States and Canada addresses.
Radar.validateAddress() takes a complete address in structured fields and returns a standardized address and a result.verificationStatus. Send city, stateCode, postalCode, and countryCode, plus either number and street or a single addressLabel. See Validate an address. verified means the text matched a single known address record. It isn’t a guarantee that a carrier delivers there, and unverified doesn’t prove the address is fake.

IP geocode

Radar.ipGeocode() converts the IP address of the request to an estimated city, state, and country, with no permission and no input. The result is an estimate: an IP address locates a network, not a person. Use it for defaults the user can change, such as a preselected country, and not to decide eligibility for regulated activity. See IP geocode.

Native apps

The iOS, Android, and React Native SDKs provide the same operations, and the React Native SDK also exports an Autocomplete component. In a native text field, apply the minimum input length and debounce yourself before you call Radar.autocomplete. See iOS SDK, Android SDK, and React Native SDK.

Coverage

Coarse (city-level) geocoding and autocomplete and IP geocoding are rated great in every rated country. Fine (address-level) coverage varies: Fine autocomplete is rated good, not great, in Argentina, Ecuador, and Peru. Place search is rated good in nearly every rated country, and great in the United States.

Handle results and errors

Web SDK methods reject with a RadarError. Read its status. The component passes the same errors to onError.

Test the integration

  • Passing case: Type the start of a real address, choose a suggestion, and confirm every field is filled. Select Continue. The address is accepted with no further request.
  • Failing case: Enter a street line of random letters and select Continue. The correction message appears and nothing is accepted.
For more, see Test, troubleshoot, and go live.

Production checklist

  • The form uses the Live publishable key from configuration. No secret key is in client code.
  • Minimum input length and debounce are in place for every autocomplete input.
  • Fields stay editable after a selection, and manual entry works when suggestions are unavailable.
  • You store structured fields and the coordinate, not only formattedAddress.
  • Your rule for unverified or unmatched addresses is enforced on the backend.
  • Your interface doesn’t promise more than the result supports: “verified” isn’t “deliverable”.

Build with an agent

Copy this prompt into a coding agent that has access to your repository.

See also