Socket
Book a DemoInstallSign in
Socket

places-autocomplete

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

places-autocomplete

An autocomplete component for the Mapbox Geocoding API.

0.4.1
latest
Source
npmnpm
Version published
Weekly downloads
16
1500%
Maintainers
1
Weekly downloads
 
Created
Source

places-autocomplete

npm

This library provides an autocomplete component for the Mapbox Geocoding API.

Getting Started

Install the package:

npm install --save places-autocomplete

Import and initialize the autocomplete:

import mapboxgl from 'mapbox-gl';
import PlacesAutocomplete from 'places-autocomplete';
import 'places-autocomplete/index.css';

mapboxgl.accessToken = 'pk.abcd1234...';

const mapboxglMap = new mapboxgl.Map({
  container: document.getElementById('my-map-container'),
  style: 'mapbox://styles/mapbox/streets-v12'
});

const autocomplete = new PlacesAutocomplete({
  mapboxToken: mapboxgl.accessToken,
  mapInstance: mapboxglMap,
  debounce: 300
});

const inputEl = document.getElementById('my-input');
autocomplete.attachTo(inputEl);

The example above configures the autocomplete with a mapbox-gl map instance, allowing the autocomplete to sync the map's position to the selected autocomplete result. You can view the Mapbox GL JS docs for more information on the mapbox-gl package.

Options

The autocomplete can be configured with the following options upon initialization:

OptionDescriptionDefault
inputAn input DOM element to attach the autocomplete to.-
mapboxTokenThe Mapbox access token used for the API requests (required).-
mapInstanceA mapboxgl.Map instance, syncs map position to autocomplete.-
classNameSpecifies the class name for the autocomplete suggestions container.-
minLengthMinimum number of characters needed to trigger autocomplete.2
debounceTime in milliseconds to delay the autocomplete between keystrokes.200
preventSubmitIf true, prevents the input from submitting its form on Enter.false
limitNumber of results to return in the autocomplete.6
languageLanguage of returned Mapbox autocomplete results.browser language
proximityFavor results that are closer to this location. Given as a string of two comma-separated coordinates ("lon,lat"). If a mapInstance is specified then the map's current center position will be used instead.-
featureTypesFilter results to include only a subset of the available feature types. Multiple types can be comma-separated. Options are: country, region, postcode, district, place, locality, neighborhood, address, and poi.-
additionalResultsPrependIf true, prepends additionalResults entries to autocomplete suggestions.false
onClearFunction called when input is cleared.-
onSelectFunction called when autocomplete item is selected (args: [item]).-
additionalResultsFunction called before updating autocomplete results, should return array of results (args: [query]).-
customizeFunction called before rendering autocomplete results (args: [input, inputRect, container, maxHeight]).-

License

The library is available as open source under the terms of the MIT License.

Keywords

autocomplete

FAQs

Package last updated on 26 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.