🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
API Reference / API Parameters / insidePolygon
Type: list of floats
Engine default: null
Parameter syntax
insidePolygon => [
  [
    p1_lat,
    p1_lng,
    p2_lat,
    p2_lng,
    p3_lat,
    p3_lng,
    ...
  ],
  [ ... ] // You can search in multiple polygons
]

Can be used in these methods:

About this parameter

Search inside a polygon (using geographical coordinates).

A polygon is a series of 3 to 10,000 points, with each point consisting of two floats representing latitude and longitude. A polygon, therefore, needs an even number of values. For example: insidePolygon=47.3165,4.9665,47.3424,5.0201,47.32,4.98. Depending on the shape and size of your polygon, points can be from 1 meter to thousands of meters apart.

Usage notes

  • insidePolygon may not be the best option for your requirements:

    • If you want to use a circle, use aroundRadius
    • If you want to use a rectangle or square, use insideBoundingBox. Don’t use insideBoundingBox and insidePolygon. If you do, only insideBoundingBox actions will run.
  • aroundLatLng and aroundLatLngViaIP will be ignored if used with insidePolygon.
  • To return all values inside the polygon, send an empty query ('')
  • Ensure your polygon doesn’t cross the 180th meridian.

    Multiple polygons

To specify multiple polygons, pass a list of floating point arrays. For example: [[47.3165, 4.9665, 47.3424, 5.0201, 47.32, 4.9], [40.9234, 2.1185, 38.6430, 1.9916, 39.2587, 2.0104]].

Examples

Search inside a polygon

1
2
3
4
5
6
7
8
9
10
11
12
$polygon = [
  46.650828100116044, // p1Lat
  7.123046875, // p1Lng
  45.17210966999772, // p2Lat
  1.009765625, // p2Lng
  49.62625916704081, // p3Lat
  4.6181640625 // p3Lng
];

$results = $index->search('query', [
  'insidePolygon' => [$polygon]
]);

Search inside multiple polygons

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$polygon1 = [
  46.650828100116044, // p1Lat
  7.123046875, // p1Lng
  45.17210966999772, // p2Lat
  1.009765625, // p2Lng
  49.62625916704081, // p3Lat
  4.6181640625 // p3Lng
];

$polygon2 = [
  49.62625916704081, // p1Lat
  4.6181640625 // p1Lng
  47.715070300900194 // p2Lat
  0.482421875 // p2Lng
  45.17210966999772, // p3Lat
  1.009765625, // p3Lng
  50.62626704081, // p4Lat
  4.6181640625 // p4Lng
];

$results = $index->search('query', [
  'insidePolygon' => [
    $polygon1,
    $polygon2
  ]
]);
Did you find this page helpful?