Setting the file. One moment.
Chapter 13 · Mapbox Search Patterns
Subchapter 13.2
references/optimization-combining.mdMarkdown4 KBView on GitHub
Pattern: Geocode once, reuse coordinates
// GOOD
1. User enters "Seattle"
2. Geocode "Seattle" → (lng, lat)
3. Use those coordinates for multiple category searches
4. Cache coordinates for session
// BAD
1. Geocode "Seattle" for coffee search
2. Geocode "Seattle" again for restaurant search
3. Geocode "Seattle" again for hotel search| UI Context | Recommended Limit |
|---|---|
| Autocomplete dropdown | 5 |
| List view | 10 |
| Map view | 25 |
| Export/download | 25 (or paginate) |
After getting search results:
1. category_search_tool → Get POIs
2. distance_tool (offline) → Calculate distances
3. bearing_tool (offline) → Get directionsWhy: Search once (API), then use offline tools for calculations (free, fast)
1. category_search_tool({category: "hospital", proximity: user_location})
→ Returns 10 hospitals with coordinates
2. distance_tool(user_location, each_hospital)
→ Calculate exact distances offline
3. Sort by distance1. search_and_geocode_tool({q: "Space Needle"})
→ Get destination coordinates
2. directions_tool({from: user_location, to: space_needle_coords})
→ Get turn-by-turn directions1. search_and_geocode_tool({q: "warehouse"})
→ Get warehouse coordinates
2. isochrone_tool({coordinates: warehouse, time: 30, profile: "driving"})
→ Get 30-minute delivery zone polygon
3. point_in_polygon_tool(customer_address, delivery_zone)
→ Check if customer is in delivery zone1. category_search_tool({category: "restaurant", limit: 10})
→ Get restaurant coordinates
2. static_map_image_tool({
markers: restaurant_coordinates,
auto_fit: true
})
→ Create map image showing all restaurantsPossible reasons:
resource_reader_tool with mapbox://categories to see valid categoriesExample recovery:
1. category_search_tool({category: "taco"}) → No results
2. Check: Is "taco" a valid category?
→ Use category_list_tool → See "mexican_restaurant" is valid
3. Retry: category_search_tool({category: "mexican_restaurant"}) → SuccessPossible reasons:
auto_complete: trueGet valid categories: Use resource_reader_tool or category_list_tool
resource_reader_tool({uri: "mapbox://categories"})Returns: All valid category IDs (e.g., “restaurant”, “hotel”, “gas_station”)
When to use:
Example mapping:
Works with: