API Reference / API Parameters / insidePolygon
Jan. 14, 2019

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 (in geo coordinates).

A polygon is an unlimited series of points, with a minimum of 3.

A point is a set of 2 floats: latitude, longitude.

The polygon therefore needs an even number of float values: p1Lat, p1Lng, p2Lat, p2Lng, p3Lat, p3Long.

For example: insidePolygon=47.3165,4.9665,47.3424,5.0201,47.32,4.98

Usage notes:

  • You can plot points that are 1 meter apart or 1000s of meters apart. This all depends on the oddness of the shape and its geographical size.

  • multiple polygons You may specify multiple polygons, in which case the search will use the union (OR) of the polygons. To specify multiple polygons, pass an list of lists of floats (each inner array must contain an even number of values, with a minimum of 6); 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]].

  • Keep in mind the purpose of this setting. For example, if you are drawing a circle, you will use instead aroundRadius. If a rectangle, then insideBoundingBox. And so on.

  • aroundLatLng and aroundLatLngViaIP will be ignored if used along with this parameter.

  • Be careful when your coordinates cross over the 180th meridian.

Examples

Search inside a polygon area

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 polygon areas

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?