Skip to main content
This widget is deprecated and will be removed in InstantSearch.js 5.0. The Algolia Places service is no longer offered.
The places widget sets the geolocation value for search based on a selected result from the Algolia Places autocomplete. It integrates location-based filtering into your search interface.

Usage

import places from 'places.js';

const placesWidget = instantsearch.widgets.places({
  placesReference: places,
  defaultPosition: ['48.8566', '2.3522'], // Paris coordinates
});

search.addWidget(placesWidget);

Examples

Basic Places Widget

import places from 'places.js';

instantsearch.widgets.places({
  placesReference: places,
});

With Default Position

import places from 'places.js';

instantsearch.widgets.places({
  placesReference: places,
  defaultPosition: ['40.7128', '-74.0060'], // New York coordinates
});

With Places Options

import places from 'places.js';

instantsearch.widgets.places({
  placesReference: places,
  container: '#places-input',
  type: 'city',
  countries: ['US', 'CA'],
  language: 'en',
});

Options

placesReference
function
required
The Algolia Places reference to use. This should be the places function imported from the places.js library.See the Algolia Places documentation for more details.
defaultPosition
string[]
The default position when the input is empty. Expects an array with latitude and longitude as strings.
['48.8566', '2.3522'] // Paris
container
string | HTMLElement
CSS Selector or HTMLElement for the Places autocomplete input. This is passed to the Places.js library.
type
string
Restricts the search to a specific type of location. Possible values:
  • 'city'
  • 'country'
  • 'address'
  • 'busStop'
  • 'trainStation'
  • 'townhall'
  • 'airport'
countries
string[]
Restricts the search to specific countries. Expects an array of ISO 3166-1 alpha-2 country codes.
['US', 'CA', 'MX']
language
string
The language to use for the Places autocomplete. Uses ISO 639-1 language codes.
aroundLatLngViaIP
boolean
Whether to bias results around the user’s location based on their IP address.
aroundLatLng
string
Force the search to be biased around a specific location. Format: "lat,lng"
"48.8566,2.3522"

Behavior

When a user selects a location from the Places autocomplete:
  1. The widget sets the aroundLatLng search parameter to the selected location’s coordinates
  2. It disables aroundLatLngViaIP to use the exact location
  3. It triggers a new search with the location-based filtering
When the user clears the input:
  1. If a defaultPosition is set, the search uses those coordinates
  2. Otherwise, it reverts to the initial aroundLatLngViaIP setting

Migration

Since Algolia Places is deprecated, consider using alternative location search services or implementing a custom solution using the configure widget to set geolocation parameters.