2 min read

Mapbox custom geocoding results 🛸

Creating a web application with search features, whether this is a broad application or something as minimal as gas stations in a zip code, you've most likely wanted to get custom mapbox geocoding results.
Mapbox custom geocoding results 🛸
Photo by FLY:D / Unsplash

Creating a web application with search features, whether this is a broad application or something as minimal as gas stations in a zip code, you've most likely wanted to get custom Mapbox geocoding results.

See the full code on my GitHub:

GitHub - ShrimpandGits/atx_downtown_geocode: Searching geocode results and limiting them to downtown Austin with Mapbox BBox property
Searching geocode results and limiting them to downtown Austin with Mapbox BBox property - GitHub - ShrimpandGits/atx_downtown_geocode: Searching geocode results and limiting them to downtown Aust...

I stumbled on this issue earlier this week when a post on reddit mentioned some issues when using the Mapbox geocoding feature to "edit search results." On looking at their posted code, the question was backwards. Instead of trying to code for locations, they should tell the geocoding api where to look.

This is done with a parameter known as setBBox in the geocoding api.

the GitHub documentation 

I wasn't sure at first how to solve this issue so I started working with my own idea. I thought, what if I wanted to search downtown Austin for places of interest. How would I limit that geocoding result to simply downtown?

my two min and max values 

To quickly create my own bbox perimeters I used geojson.io to create some rough bounds for downtown Austin.

Keep in mind, per the documentation:

Parameters

  • bbox Array<Number> a bounding box given as an array in the format [minX, minY, maxX, maxY].

Which means that you have to adjust and play with your values for the bounds to make sure they are formatted correctly. Mine were not and kept throwing a "trouble connecting to the server" error in the search box.

searching for stubbs bbq and setting a marker 

The final result allowed me to search for Cava (one of my favorite places) which has many locations in ATX, however the results only returned the one at Congress at 6th street, limiting our search results to our bounds.

Read the full tutorial here:

Local search with the Geocoding API | Help
This tutorial guides you through the process of creating a local search app using optional parameters from the Mapbox Geocoding API.