insidePolygon

scope search
type geo polygon(s)
default null
description

Search inside a polygon (in geo coordinates).

The polygon is defined by a set of points (minimum 3), each defined by its latitude and longitude. You therefore need an even number of floats, with a minimum of 6: p1Lat, p1Lng, p2Lat, p2Lng, p3Lat, p3Long.

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

You may specify multiple polygons, in which case the search will use the union (OR) of the polygons. To specify multiple polygons, pass an array of arrays 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]].

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

Examples

Search inside a polygon area

<?php
$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]
]);
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]
})
const polygon = [
  46.650828100116044, // p1Lat
  7.123046875, // p1Lng
  45.17210966999772, // p2Lat
  1.009765625, // p2Lng
  49.62625916704081, // p3Lat
  4.6181640625 // p3Lng
];

index.search({
  query: 'query',
  insidePolygon: [polygon]
}).then(res => {
  // console.log(res);
});
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]
})
let polygon = [LatLng(lat: 46.650828100116044, lng: 7.123046875), LatLng(lat: 45.17210966999772, lng: 1.009765625 ), LatLng(lat: 49.62625916704081, lng: 4.6181640625), LatLng(lat: 47.715070300900194, lng: 0.482421875 )]

let query = Query(query: "query")
query.insidePolygon = [polygon]

index.search(query, completionHandler: { (res, error) in
    print(res)
})
index.search(new Query("query").setInsidePolygon(new Polygon(
    new LatLng(46.650828100116044, 7.123046875),
    new LatLng(45.17210966999772, 1.009765625),
    new LatLng(49.62625916704081, 4.6181640625))));
index.search(
  new Query("query")
    .AddInsidePolygon(46.650828100116044f, 7.123046875f)
    .AddInsidePolygon(45.17210966999772f, 1.009765625f)
    .AddInsidePolygon(49.62625916704081f, 4.6181640625f)
);
index.search(
  new Query("query").setInsidePolygon(Arrays.asList(
    "46.650828100116044, 7.123046875, 45.17210966999772, 1.009765625, 49.62625916704081, 4.6181640625"
  ))
);
res, err := index.Search("query", algoliasearch.Map{
    "insidePolygon": [][]float64{
        []float64{
            46.650828100116044, // p1Lat
            7.123046875,        // p1Lng
            45.17210966999772,  // p2Lat
            1.009765625,        // p2Lng
            49.62625916704081,  // p3Lat
            4.6181640625,       // p3Lng
        },
    },
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    insidePolygon = Some(Seq(
      InsidePolygon(46.650828100116044, 7.123046875, 45.17210966999772, 1.009765625, 49.62625916704081, 4.6181640625)
    ))
  )
}

Search inside multiple polygon areas

<?php
$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]
]);
polygon1 = [
  46.650828100116044, # p1Lat
  7.123046875, # p1Lng
  45.17210966999772, # p2Lat
  1.009765625, # p2Lng
  49.62625916704081, # p3Lat
  4.6181640625 # p3Lng
]

polygon2 = [
  49.62625916704081, # p1_lat
  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]
})
var polygon1 = [
  46.650828100116044, // p1Lat
  7.123046875, // p1Lng
  45.17210966999772, // p2Lat
  1.009765625, // p2Lng
  49.62625916704081, // p3Lat
  4.6181640625 // p3Lng
];

var 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
];

index.search({
  query: 'query',
  insidePolygon: [polygon1, polygon2]
}).then(res => {
  // console.log(res);
});
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]
})
let polygon1 = [LatLng(lat: 46.650828100116044, lng: 7.123046875), LatLng(lat: 45.17210966999772, lng: 1.009765625 ), LatLng(lat: 49.62625916704081, lng: 4.6181640625), LatLng(lat: 47.715070300900194, lng: 0.482421875 )]

let polygon2 = [LatLng(lat: 47.650828100116044, lng: 6.123046875), LatLng(lat: 46.17210966999772, lng: 1.009765625 ), LatLng(lat: 48.62625916704081, lng: 3.6181640625), LatLng(lat: 45.715070300900194, lng: 0.482421875 )]

let query = Query(query: "query")
query.insidePolygon = [polygon1, polygon2]

index.search(query, completionHandler: { (res, error) in
    print(res)
})
index.search(new Query("query").setInsidePolygon(
    new Polygon(
        new LatLng(46.650828100116044, 7.123046875),
        new LatLng(45.17210966999772, 1.009765625),
        new LatLng(49.62625916704081, 4.6181640625)),
    new Polygon(
        new LatLng(49.62625916704081, 4.6181640625),
        new LatLng(47.715070300900194, 0.482421875),
        new LatLng(49.62625916704081, 1.009765625),
        new LatLng(50.62626704081, 4.6181640625)))
);
index.search(
  new Query("query")
    .AddInsidePolygon(46.650828100116044f, 7.123046875f)
    .AddInsidePolygon(45.17210966999772f, 1.009765625f)
    .AddInsidePolygon(49.62625916704081f, 4.6181640625f)

    .AddInsidePolygon(49.62625916704081f, 4.6181640625f)
    .AddInsidePolygon(47.715070300900194f, 0.482421875f)
    .AddInsidePolygon(45.17210966999772f, 1.009765625f)
    .AddInsidePolygon(50.62626704081f, 4.6181640625"f)

);
index.search(
  new Query("query").setInsidePolygon(Arrays.asList(
    "46.650828100116044, 7.123046875, 45.17210966999772, 1.009765625, 49.62625916704081, 4.6181640625",
    "49.62625916704081, 4.6181640625, 47.715070300900194, 0.482421875, 45.17210966999772, 1.009765625, 50.62626704081, 4.6181640625"
  ))
);
res, err := index.Search("query", algoliasearch.Map{
    "insidePolygon": [][]float64{
        []float64{
            46.650828100116044, // p1Lat
            7.123046875,        // p1Lng
            45.17210966999772,  // p2Lat
            1.009765625,        // p2Lng
            49.62625916704081,  // p3Lat
            4.6181640625,       // p3Lng
        },
        []float64{
            49.62625916704081,  // p1Lat
            4.6181640625,       // p1Lng
            47.715070300900194, // p2Lat
            0.482421875,        // p2Lng
            45.17210966999772,  // p3Lat
            1.009765625,        // p3Lng
            50.62626704081,     // p4Lat
            4.6181640625,       // p4Lng
        },
    },
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    insidePolygon = Some(Seq(
      InsidePolygon(46.650828100116044, 7.123046875, 45.17210966999772, 1.009765625, 49.62625916704081, 4.6181640625),
      InsidePolygon(49.62625916704081, 4.6181640625, 47.715070300900194, 0.482421875, 45.17210966999772, 1.009765625, 50.62626704081, 4.6181640625)
    ))
  )
}
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala