Geocoding limit results by a drawn area

To ensure that search results are limited to the specific area drawn on the map, utilize the geocode control’s bbox (bounding box) feature. By drawing a polygon on the map, you can filter the search results to only include data within the bounds of the polygon. For a comprehensive list of geocoding control options, refer to the Geocoding control’s reference documentation.

In this example, we use the mapbox-gl-draw-rectangle-restrict-area plugin to draw rectangles on the map.

Click outside the rectangle when you draw the final vertex to complete the polygon.



Learn more

Discover the process of integrating the geocoding control feature into your React (Geocoding React component) or Svelte (Geocoding Svelte component) applications. Additionally, you have the option to use the VanillaJS version to customize it for any of your applications.

Are you currently using a different map library? No worries! Learn how to incorporate the geocoding control functionality with Leaflet (Leaflet Geocoding control), OpenLayers (OpenLayers Geocoding control), or MapLibre GL JS (MapLibre GL JS Geocoding control).

Related examples

An extension of MapLibre GL JS