Skip to main content
  • Type: list<number>
  • Default: null
  • Scope: search
The insidePolygon parameter restricts search results to records located within one or more geographic polygons. Each polygon is defined by a series of latitude/longitude points (lat1, lng1, lat2, lng2, …), with at least 3 points (6 values). You can specify:
  • A single polygon as a flat list of numbers
  • Multiple polygons as a list of such lists

Usage

  • Minimum of 3 coordinate pairs (6 values) per polygon
  • Up to 10,000 coordinate pairs supported per request
  • If both insidePolygon and insideBoundingBox are specified, only insideBoundingBox is applied
  • aroundLatLng and aroundLatLngViaIP will be ignored if used with insidePolygon.
  • To match all records within the polygon, send an empty query ("")
  • Avoid polygons that cross the 180th meridian

Examples

Search inside a single polygon

Current API clients

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,
        },
      },
    }
  )
);
index.Search(new Query("query")
{
    InsidePolygon = new List>
    {
        new List
        {
            46.650828100116044f,
            7.123046875f,
            45.17210966999772f,
            1.009765625f,
            49.62625916704081f,
            4.6181640625f
        }
    }
});

Search inside multiple polygons

Current API clients

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,
        },
      },
    }
  )
);
index.Search(new Query("query")
{
    InsidePolygon = new List>
    {
        new List
        {
            46.650828100116044f,
            7.123046875f,
            45.17210966999772f,
            1.009765625f,
            49.62625916704081f,
            4.6181640625f
        }
    }
});

Search inside multiple polygons

Current API clients

index.Search(new Query("query")
{
    InsidePolygon = new List>
    {
        new List
        {
            46.650828100116044f,
            7.123046875f,
            45.17210966999772f,
            1.009765625f,
            49.62625916704081f,
            4.6181640625f
        },
        new List
        {
            49.62625916704081f,
            4.6181640625f,
            47.715070300900194f,
            0.482421875f,
            45.17210966999772f,
            1.009765625f,
            50.62626704081f,
            4.6181640625f
        }
    }
});
index.Search(new Query("query")
{
    InsidePolygon = new List>
    {
        new List
        {
            46.650828100116044f,
            7.123046875f,
            45.17210966999772f,
            1.009765625f,
            49.62625916704081f,
            4.6181640625f
        },
        new List
        {
            49.62625916704081f,
            4.6181640625f,
            47.715070300900194f,
            0.482421875f,
            45.17210966999772f,
            1.009765625f,
            50.62626704081f,
            4.6181640625f
        }
    }
});