Source: https://developers.woosmap.com/products/localities/reference/libraries/widget/2.0/

> For clean Markdown of any page, append `.md` to the page URL.

> For a complete documentation index, see https://developers.woosmap.com/llms.txt

# Localities Widget Reference 2.0



## Autocomplete class

`woosmap.localities.Autocomplete`

This class extends `AutocompleteElementsHandler`. 

Autocomplete

### Constructor

#### `Autocomplete`

`Autocomplete(inputId, customConfig?)`

**Parameters:**
- `inputId`: `String` id attribute for the input hosting the Autocomplete widget
- `customConfig`: `AutocompleteParameters` config object

  

### Methods

#### `addListener`

`addListener(eventName, callback)`

**Parameters:**
- `eventName`: `String` name of the event
- `callback`: `Function` executed through addEventListener

**Return Type** : `Event`

Adds an event listener to the widget Can be removed using removeListener() with the same arguments

#### `removeListener`

`removeListener(eventName, callback)`

**Parameters:**
- `eventName`: `String` name of the event
- `callback`: `Function` callback to remove, exactly as added to addListener

Removes given event listener from the widget

#### `getSelectedSuggestionDetails`

`getSelectedSuggestionDetails()`

**Parameters:** None

**Return Type** : `DetailsResponseItem`

Returns the latest user-selected locality among search results

#### `getAutocompleteSuggestions`

`getAutocompleteSuggestions()`

**Parameters:** None

**Return Type** : `AutocompleteResponse`

Returns the latest search results

#### `setTypes`

`setTypes(types)`

**Parameters:**
- `types`: `String` The types queried (example ‘locality’, ‘postal\_code’, ‘country’ ; omit param for ‘locality’ + ‘postal\_code’)

Sets the types to query

#### `setCustomDescription`

`setCustomDescription(customDescription)`

**Parameters:**
- `customDescription`: `String` The customDescription

Sets the custom description to query

#### `setComponentRestrictions`

`setComponentRestrictions(components)`

**Parameters:**
- `components`: `ComponentRestrictions` restricts predictions to selected components

Sets the component restrictions

#### `setOptions`

`setOptions(customConfig)`

**Parameters:**
- `customConfig`: `AutocompleteParameters` 

Sets new config options

  

## AutocompleteParameters Interface

### Properties

#### `components`

**Type** : ` ComponentRestrictions`

restricts predictions to selected components

#### `customDescription`

**Type** : ` String`

This parameter allows to choose the description format for all or some of the suggestion types selected. The custom formats are described as follows:

```javascript
custom_description=type_A:"{field_1}, {field_2}, [...]"|type_B:"{field_1}, {field_2}, [...]"
```

#### `data`

**Type** : ` String`

Defaults to ‘standard’, can be set to ‘advanced’ to retrieve postal codes outside western Europe

#### `debounceTime`

**Type** : ` Number`

prevents autocomplete requests from being sent unnecessarily often. Default is no debounce.

#### `extended`

**Type** : ` String`

can be set to ‘postal\_code’ to search localities by name or postal codes

#### `firstTabIndex`

**Type** : ` Number`

all tabindexes in Autocomplete will start from that tabindex. Defaults to 0.

#### `language`

**Type** : ` String`

expected response language. Default is the country local or browser language

#### `location`

**Type** : ` LatLngLiteral`

This parameter is used to add a bias to the autocomplete feature. The location defines the point around which to retrieve results in priority.

#### `minLength`

**Type** : ` Number`

Number of characters before sending request to Localities API

#### `types`

**Type** : ` String`

The types queried (example ‘locality’, ‘postal\_code’, ‘country’ ; omit param for ‘locality’ + ‘postal\_code’)

  

## AutocompleteResponse Interface

### Properties

#### `localities`

**Type** : ` AutocompleteResponseItem`

Array with Autocomplete items

  

## AutocompleteResponseItem Interface

### Properties

#### `description`

**Type** : ` String`

The suggested formatted answer

#### `matched_substrings`

**Type** : ` array`

Contains an array with offset value and length. These describe the location of the entered term in the prediction result text, so that the term can be highlighted if desired.

#### `public_id`

**Type** : ` String`

Item identifier

#### `type`

**Type** : ` String`

requested prediction type (‘locality’, ‘postal\_code’, ‘country’, ‘admin\_level’, ‘train\_station’, ‘metro\_station’, ‘shopping’, ‘airport’, ‘museum’, ‘zoo’, ‘amusement\_park’, ‘art\_gallery’, ‘tourist\_attraction’, ‘address’)

  

## ComponentRestrictions Interface

### Properties

#### `country`

**Type** : ` String`

Restricts predictions to the specified country (ISO 3166-1 Alpha-2 country code, case insensitive). For example, ‘fr’, ‘gb’, or ‘es’. You can provide a single one, or an array of country code strings.

  

## DetailsResponseItem Interface

### Properties

#### `address_components`

**Type** : ` array`

Array containing the separate components applicable to this address. Each component has a long name (full text description or name of the address component), a short name (abbreviated textual name for the address component, if available) and types (array indicating the type of the address component like `locality`, `street_number`…)

#### `formatted_address`

**Type** : ` string`

String containing the human-readable address of this item.

#### `geometry`

**Type** : ` object`

Item geometry (`{location:{lat, lng}, viewport: {northeast: {lat, lng}, southwest: {lat, lng}}}`)

#### `name`

**Type** : ` string`

Item name

#### `public_id`

**Type** : ` string`

Item identifier

#### `types`

**Type** : ` array`

Types of the given item (like `locality` or `postal_code`)
