Skip to main content
Signature

Import

See this widget in action

Preview this widget and its behavior.

About this widget

The geoSearch widget lets you search for results based on their position within a specified area (a bounding box). It also provides features such as “search on map interactions”.
The geoSearch widget doesn’t let you search around a central point or within polygons. If you want this, you need to build your own UI on top of the Algolia API.

Requirements

  • Your hit records must have a _geoloc attribute so they can be displayed on the map.
  • You must load the Google Maps library and pass a reference to the widget: the library doesn’t come with InstantSearch.js.
  • You must explicitly set the map container’s height. For example:
CSS

Examples

JavaScript

Options

string | HTMLElement
required
The CSS Selector or HTMLElement to insert the widget into.
object
required
The reference to the global window.google object.
JavaScript
number
default:1
By default, the map sets the zoom level based on the displayed markers (results). However, after InstantSearch has applied a refinement, there may be no results. When this happens, a specific zoom level is required to render the map.
JavaScript
object
default:"{lat: 0, lng: 0}"
By default, the map sets the position based on the displayed markers (results). However, after InstantSearch has applied a refinement, there may be no results. When this happens, a specific position is required to render the map.
JavaScript
object
The options forwarded to the Google Maps constructor.
JavaScript
object
The options for customizing the built-in Google Maps markers. This is ignored when the customHTMLMarker is provided. The object accepts multiple attributes:
  • createOptions: function. A function to create the options passed to the Google Maps marker. The function is called with item, which is the hit tied to the marker.
  • events: object. An object that takes event types (such as click and mouseover) as keys and listeners as values. The listener is called with an object that contains properties event, item, marker, and map.
JavaScript
object
The options for customizing the HTML marker. InstantSearch.js provides an alternative to the built-in Google Maps markers. You can use plain HTML to build your custom markers (see templates.HTMLMarker). The customHTMLMarker object accepts several attributes:
  • createOptions: function. A function to create the options passed to the HTMLMarker. The only supported option is anchor. It lets you shift the marker position from the center of the element.
  • events: object. An object that takes event types (such as click and mouseover) as keys and listeners as values. The listener is called with an object that contains properties event, item, marker, and map.
JavaScript
boolean
default:true
If true, the map is used for refining the search. Otherwise, it’s only for display purposes.
JavaScript
boolean
default:true
If true, a button is displayed on the map to allow users to clear any refinements.
JavaScript
boolean
default:true
If true, users can toggle the option enableRefineOnMapMove directly from the map.
JavaScript
boolean
default:true
If true, refine is triggered as you move the map.
JavaScript
object
The templates to use for the widget.
JavaScript
object
default:"{}"
The CSS classes you can override:
  • root. The widget’s root element.
  • map. The map element.
  • control. The control element.
  • label. The label for the control element.
  • selectedLabel. The control element’s selected label.
  • input. The control element’s input.
  • redo. The “Redo search” button.
  • disabledRedo. The disabled “Redo search” button.
  • reset. The “Reset refinement” button.
JavaScript

Templates

You can customize parts of a widget’s UI using the Templates API. Each template includes an html function, which you can use as a tagged template. This function safely renders templates as HTML strings and works directly in the browser—no build step required. For details, see Templating your UI.
The html function is available in InstantSearch.js version 4.46.0 or later.
string | function
The template to use for the marker.
string | function
The template for the reset button.
string | function
The template for the toggle label.
string | function
The template for the redo label.

HTML output

HTML

Customize the UI with connectGeoSearch

If you want to create your own UI of the geoSearch widget, you can use connectors. To use connectGeoSearch, you can import it with the declaration relevant to how you installed InstantSearch.js.
Then it’s a 3-step process:
JavaScript

Create a render function

This rendering function is called before the first search (init lifecycle step) and each time results come back from Algolia (render lifecycle step).
JavaScript

Rendering options

The following rendering option example code snippets use Leaflet to render the map. If you prefer not to use Leaflet, you can use another library (such as Google Maps or Mapbox).
object[]
Hits that matched the search request.
JavaScript
object
The current search position, when applicable.
JavaScript
object
The search’s bounding box:
  • northEast: { lat: number, lng: number }. The top right corner of the map view.
  • southWest: { lat: number, lng: number }. The bottom left corner of the map view.
function
Sets a bounding box to filter the results from the given map bounds. The function accepts an object with:
  • northEast: { lat: number, lng: number }. The top right corner of the map view.
  • southWest: { lat: number, lng: number }. The bottom left corner of the map view.
(eventType, hit, eventName) => void
The function to send click or conversion events. The view event is automatically sent when this connector renders hits. To learn more, see the insights middleware.
  • eventType: 'click' | 'conversion'
  • hit: Hit | Hit[]
  • eventName: string
JavaScript
function
Resets the current bounding box refinement.
function
Returns true if the current refinement is set with the map bounds.
function
Toggles whether users can refine on map move.
function
Returns true if users can refine on map move.
function
Indicates that the map has moved since the last refinement. This function should be called on each map move. It helps ensure the map is only re-rendered when it has moved.
function
Returns true if the map has moved since the last refinement.
object
All original widget options forwarded to the render function.

Create and instantiate the custom widget

First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:
  • Instance parameters. Predefined options that configure Algolia’s behavior.
  • Custom parameters. Parameters you define to make the widget reusable and adaptable.
Inside the renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript

Instance options

boolean
default:true
If true, refine is triggered as you move the map.
JavaScript
function
default:"items => items"
A function that receives the list of items before they are displayed. It should return a new array with the same structure. Use this to transform, filter, or reorder the items.The function also has access to the full results data, including all standard response parameters and parameters from the helper, such as disjunctiveFacetsRefinements.
JavaScript

Full example

Last modified on July 22, 2026