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
]
Parameter syntax
insidePolygon: [
  [
    p1_lat,
    p1_lng,
    p2_lat,
    p2_lng,
    p3_lat,
    p3_lng,
    ...
  ],
  [ ... ] # you can search in multiple polygons
]
Parameter syntax
insidePolygon: [
  [
    p1_lat,
    p1_lng,
    p2_lat,
    p2_lng,
    p3_lat,
    p3_lng,
    ...
  ],
  [ ... ] // you can search in multiple polygons
]
Parameter syntax
'insidePolygon': [
  [
    p1_lat,
    p1_lng,
    p2_lat,
    p2_lng,
    p3_lat,
    p3_lng,
    ...
  ],
  [ ... ] # you can search in multiple polygons
]
Parameter syntax
.setInsidePolygon(
  new Polygon(
    new LatLng(p1_lat, p1_lng),
    new LatLng(p2_lat, p2_lng),
    new LatLng(p3_lat, p3_lng),
    ...
  ),
  new Polygon( // you can search in multiple polygons
    ...
  )
)
Parameter syntax
.AddInsidePolygon(p1_lat, p1_lng)
.AddInsidePolygon(p2_lat, p2_lng)
.AddInsidePolygon(p3_lat, p3_lng)
Parameter syntax
.setInsidePolygon(
  Arrays.asList(
    "p1_lat, p1_lng, p2_lat, p2_lng, p3_lat, p3_lng, ...",
    ... // you can search in multiple polygons
  )
)
Parameter syntax
"insidePolygon": [][]float64{
  []float64{
    p1_lat,
    p1_lng,
    p2_lat,
    p2_lng,
    p3_lat,
    p3_lng,
  },
  []float64{ // you can search in multiple polygons
    ...
  }
}
Parameter syntax
insidePolygon = Some(Seq(
  InsidePolygon(
    p1_lat,
    p1_lng,
    p2_lat,
    p2_lng,
    p3_lat,
    p3_lng,
    ...
  ),
  InsidePolygon( // you can search in multiple polygons
    ...
  )
))

Can be used in these methods:
search, browse, deleteBy, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, browse, delete_by, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, browse, deleteBy, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, browse, delete_by, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, browse, deleteBy, searchForFacetValues searchAsync, browseAsync, deleteByAsync, searchForFacetValues Search, Browse, DeleteBy, SearchForFacetValues, GenerateSecuredApiKey, AddApiKey, UpdateApiKey Search, browse, deleteBy, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey Search, Browse, 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 (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 meridia.

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)))
);
Not implemented in this api client
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