connectGeoSearch
connector.
Working example
The complete source code of the example on this page is available on GitHub.This code has been specifically created for Vue 2. Some modifications may be required for it to work correctly in Vue 3.
vue-googlemaps
library to access Google Maps.
Dataset
This guide use a dataset of over 3,000 records of the biggest airports in the world.JSON
_geoloc
attribute to enable geo-filtering and geo-sorting.
You can download the dataset on GitHub.
Have a look at how to import it in Algolia.
Configure index settings
When displaying on a map, you still want the relevance to be good. For that, configure the index as follows:- Searchable attributes should be set to enable search in the four textual attributes:
name
,city
,country
, andiata_code
. - Custom ranking: use the number of other connected airports
links_count
as a ranking metric. The more connections the better.
Displaying hits
First of all, start by adding thevue-googlemaps
library:
JavaScript
connectGeoSearch
:
Vue
this.state.items
to display the hits from this search:
Going further
This guide only explains how to display hits on a map, butconnectGeoSearch
connector has more features, such as refining the search when the map moves and automatically centering on the correct items.
Feel free to explore the options given to state
from the connector to make these experiences.