Skip to main content
In this tutorial, you’ll learn how to filter results around a polygonal location. This location can either be set manually or taken from the current user position.

Dataset

The guide uses a dataset of the 3,000+ biggest airports in the world.
JSON
[
 {
    "objectID": "3797",
    "name": "John F Kennedy Intl",
    "city": "New York",
    "country": "United States",
    "iata_code": "JFK",
    "_geoloc": {
      "lat": 40.639751,
      "lng": -73.778925
    },
    "links_count": 911
  }
]
To tell Algolia where each record is located, the latitude and longitude must be stored in the _geoloc attribute.

Initialize the client

  1. Download the data set
  2. Set up an API client and send your data to Algolia

Configure index settings

Even if you just want to sort by distance to a location, your textual relevance should also be good so that users can refine the search with a query. To do that, you must configure the . The searchable attributes are: name, city, country, and iata_code.
var response = await client.SetSettingsAsync(
  "ALGOLIA_INDEX_NAME",
  new IndexSettings
  {
    SearchableAttributes = new List<string> { "name", "country", "city", "iata_code" },
    CustomRanking = new List<string> { "desc(links_count)" },
  }
);

Filtering inside a polygonal area

The USA can be considered as a polygon:
Screenshot of a map showing the United States with a polygonal filter drawn over it, highlighting a specific region.
To filter inside this rectangle, you need to pass the latitude and longitude of all the points to the insidePolygon parameter:
  • 42.01,-124.31,
  • 48.835509470063045,-124.40453125000005
  • 45.01082951668149,-65.95726562500005
  • 31.247243545293433,-81.06578125000004
  • 25.924152577235226,-97.68234374999997
  • 32.300311895879545,-117.54828125
var response = await client.SearchSingleIndexAsync<Hit>(
  "ALGOLIA_INDEX_NAME",
  new SearchParams(
    new SearchParamsObject
    {
      InsidePolygon = new List<List<Double>>
      {
        new List<Double>
        {
          42.01,
          -124.31,
          48.835509470063045,
          -124.40453125000005,
          45.01082951668149,
          -65.95726562500005,
          31.247243545293433,
          -81.06578125000004,
          25.924152577235226,
          -97.68234374999997,
          32.300311895879545,
          -117.54828125,
        },
      },
    }
  )
);
The empty query ('') returns all matching airports.
Last modified on February 19, 2026