insidePolygon
null
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:
search,
browseObjects,
deleteBy,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
delete_by,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browseObjects,
deleteBy,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
delete_by,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
deleteBy,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
browseObjects,
deleteObjectBy,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
Browse,
DeleteBy,
SearchForFacetValues,
GenerateSecuredApiKeys,
AddApiKey,
UpdateApiKey
Search,
browse,
deleteBy,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
BrowseObjects,
DeleteBy,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
browse index,
delete by,
search into facet values,
generateSecuredApiKey,
add key,
update key
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 useinsideBoundingBox
andinsidePolygon
. If you do, onlyinsideBoundingBox
actions will run.
- If you want to use a circle, use
aroundLatLng
andaroundLatLngViaIP
will be ignored if used withinsidePolygon
.- 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
]
]);