Localities JavaScript API

Autocomplete on Localities using the Woosmap Localities JavaScript API

  1. Introduction
  2. Usage

Introduction

The Localities JavaScript API enables your users to search for any type of location, such as addresses, city names or postcodes. It’s a lightweight JavaScript library to quickly implement Localities REST API.

Add the following snippet to the <head> tag of your site.

HTML
        <script src="https://sdk.woosmap.com/localities/localities.2.0.js"></script>

    

To begin with the Localities Service, you need to build a new AutocompleteService object passing the key parameter corresponding to your project public key.

JavaScript
        const key = 'woos-xxxx'; //your project public key
let autocompleteService = new woosmap.localities.AutocompleteService(key);

    

Usage

Here is a code sample to help you use the Localities JS API.

On each keyup event fired on the dedicated text input, a getQueryPredictions() is called and results displayed below. When one of the items of the list is clicked, a getDetails() is called and the result displayed below.

To understand how to go deeper with the Localities JS API, please check the Localities JS API Reference.

Example

In this example, we use the custom_description parameter and we query the getDetails of a selected locality to get its components.

Was this article helpful?
Have more questions? Submit a request