Mapbox Search Patterns Skill
Expert guidance for AI assistants on using Mapbox search tools effectively. Covers tool selection, parameter optimization, and best practices for geocoding, POI search, and location discovery.
Available Search Tools
1. searchandgeocode_tool
Best for: Specific places, addresses, brands, named locations
Use when query contains:
- - Specific names: "Starbucks on 5th Avenue", "Empire State Building"
- Brand names: "McDonald's", "Whole Foods"
- Addresses: "123 Main Street, Seattle", "1 Times Square"
- Chain stores: "Target"
- Cities/places: "San Francisco", "Portland"
Don't use for: Generic categories ("coffee shops", "museums")
2. categorysearchtool
Best for: Generic place types, categories, plural queries
Use when query contains:
- - Generic types: "coffee shops", "restaurants", "gas stations"
- Plural forms: "museums", "hotels", "parks"
- Is-a phrases: "any coffee shop", "all restaurants", "nearby pharmacies"
- Industry terms: "electric vehicle chargers", "ATMs"
Don't use for: Specific names or brands
3. reversegeocodetool
Best for: Converting coordinates to addresses, cities, towns, postcodes
Use when:
- - Have GPS coordinates, need human-readable address
- Need to identify what's at a specific location
- Converting user location to address
Tool Selection Decision Matrix
| User Query | Tool | Reasoning |
|---|
| "Find Starbucks on Main Street" | searchandgeocodetool | Specific brand name |
| "Find coffee shops nearby" |
categorysearch_tool | Generic category, plural |
| "What's at 37.7749, -122.4194?" | reverse
geocodetool | Coordinates to address |
| "Empire State Building" | search
andgeocode_tool | Specific named POI |
| "hotels in downtown Seattle" | category
searchtool | Generic type + location |
| "Target store locations" | search
andgeocode_tool | Brand name (even plural) |
| "any restaurant near me" | category
searchtool | Generic + "any" phrase |
| "123 Main St, Boston, MA" | search
andgeocode_tool | Specific address |
| "electric vehicle chargers" | category
searchtool | Industry category |
| "McDonald's" | search
andgeocode_tool | Brand name |
Parameter Guidance
Proximity vs Bbox vs Country
Three ways to spatially constrain search results:
1. proximity (STRONGLY RECOMMENDED)
What it does: Biases results toward a location, but doesn't exclude distant matches
Use when:
- - User says "near me", "nearby", "close to"
- Have a reference point but want some flexibility
- Want results sorted by relevance to a point
Example:
CODEBLOCK0
Why this works: API returns SF pizza places first, but might include famous NYC pizzerias if highly relevant
Critical: Always set proximity when you have a reference location! Without it, results are IP-based or global.
2. bbox (Bounding Box)
What it does: Hard constraint - ONLY returns results within the box
Use when:
- - User specifies an area: "in downtown", "within this neighborhood"
- Have a defined service area
- Need to guarantee results are within bounds
Example:
CODEBLOCK1
Why this works: Guarantees all hotels are within SF's downtown area
Watch out: Too small = no results; too large = irrelevant results
3. country
What it does: Limits results to specific countries
Use when:
- - User specifies country: "restaurants in France"
- Building country-specific features
- Need to respect regional boundaries
- Or it is otherwise clear they want results within a specific country
Example:
CODEBLOCK2
Why this works: Finds Paris, France (not Paris, Texas)
Can combine: proximity + country + bbox or any combination of the three
Decision Matrix: Spatial Filters
| Scenario | Use | Why |
|---|
| "Find coffee near me" | proximity | Bias toward user location |
| "Coffee shops in downtown Seattle" |
proximity + bbox | Center on downtown, limit to area |
| "Hotels in France" | country | Hard country boundary |
| "Best pizza in San Francisco" | proximity + country ["US"] | Bias to SF, limit to US |
| "Gas stations along this route" | bbox around route | Hard constraint to route corridor |
| "Restaurants within 5 miles" | proximity (then filter by distance) | Bias nearby, filter results |
Setting limit Parameter
categorysearchtool only (1-25, default 10)
| Use Case | Limit | Reasoning |
|---|
| Quick suggestions | 5 | Fast, focused results |
| Standard list |
10 | Default, good balance |
| Comprehensive search | 25 | Maximum allowed |
| Map visualization | 25 | Show all nearby options |
| Dropdown/autocomplete | 5 | Don't overwhelm UI |
Performance tip: Lower limits = faster responses
types Parameter (searchandgeocode_tool)
Filter by feature type:
| Type | What It Includes | Use When |
|---|
| INLINECODE3 | Points of interest (businesses, landmarks) | Looking for POIs, not addresses |
| INLINECODE4 |
Street addresses | Need specific address |
|
place | Cities, neighborhoods, regions | Looking for area/region |
|
street | Street names without numbers | Need street, not specific address |
|
postcode | Postal codes | Searching by ZIP/postal code |
|
district | Districts, neighborhoods | Area-based search |
|
locality | Towns, villages | Municipality search |
|
country | Country names | Country-level search |
Example combinations:
CODEBLOCK3
Default behavior: All types included (usually what you want)
autocomplete Parameter (searchandgeocodetool)
What it does: Enables partial/fuzzy matching
| Setting | Behavior | Use When |
|---|
| INLINECODE11 | Matches partial words, typos | User typing in real-time |
| INLINECODE12 (default) |
Exact matching | Final query, not autocomplete |
Example:
CODEBLOCK4
Use for:
- - Search-as-you-type interfaces
- Handling typos ("mcdonalds" -> McDonald's)
Don't use for:
- - Final/submitted queries (less precise)
- When you need exact matches
Anti-Patterns to Avoid
Don't: Use category_search for brands
CODEBLOCK5
Don't: Use searchandgeocode for generic categories
CODEBLOCK6
Don't: Forget proximity for local searches
CODEBLOCK7
Don't: Use bbox when you mean proximity
CODEBLOCK8
Don't: Request ETA unnecessarily
CODEBLOCK9
Don't: Set limit too high for UI display
CODEBLOCK10
Quick Reference
Tool Selection Flowchart
CODEBLOCK11
Essential Parameters Checklist
For local searches, ALWAYS set:
- -
proximity (or bbox if strict boundary needed)
For category searches, consider:
- -
limit (match UI needs) - INLINECODE15 (json_string if plotting on map)
For disambiguation, use:
- -
country (when geographic context matters) - INLINECODE17 (when feature type matters)
For travel-time ranking:
- -
eta_type, navigation_profile, origin (costs API quota)
Common Mistakes
- 1. Forgetting proximity -> Results are global/IP-based
- Using wrong tool -> categorysearch for "Starbucks" (use searchandgeocode)
- Invalid category -> Check categorylist first
- Bbox too small -> No results; use proximity instead
- Requesting ETA unnecessarily -> Adds API cost
- Limit too high for UI -> Overwhelming user
- Not filtering types -> Get cities when you want POIs
Reference Files
Load these for deeper guidance on specific topics:
- -
references/advanced-params.md — poi_category, ETA, format, and language parameters references/workflows.md — Common patterns: Near Me, Branded, Geocoding, Category+Area, Reverse, Route-Based, Multilingualreferences/optimization-combining.md — Performance optimization, combining tools, handling no results, category list resource
Mapbox 搜索模式技能
关于AI助手有效使用Mapbox搜索工具的专家指南。涵盖工具选择、参数优化以及地理编码、兴趣点搜索和位置发现的最佳实践。
可用搜索工具
1. searchandgeocode_tool(搜索与地理编码工具)
最佳用途: 特定地点、地址、品牌、命名位置
当查询包含以下内容时使用:
- - 特定名称:第五大道的星巴克、帝国大厦
- 品牌名称:麦当劳、全食超市
- 地址:西雅图主街123号、时代广场1号
- 连锁店:塔吉特
- 城市/地点:旧金山、波特兰
不适用于: 通用类别(咖啡店、博物馆)
2. categorysearchtool(类别搜索工具)
最佳用途: 通用地点类型、类别、复数查询
当查询包含以下内容时使用:
- - 通用类型:咖啡店、餐厅、加油站
- 复数形式:博物馆、酒店、公园
- 类别短语:任何咖啡店、所有餐厅、附近药店
- 行业术语:电动车充电桩、自动取款机
不适用于: 特定名称或品牌
3. reversegeocodetool(反向地理编码工具)
最佳用途: 将坐标转换为地址、城市、城镇、邮政编码
使用场景:
- - 拥有GPS坐标,需要可读地址
- 需要识别特定位置的内容
- 将用户位置转换为地址
工具选择决策矩阵
| 用户查询 | 工具 | 理由 |
|---|
| 在主街找星巴克 | searchandgeocodetool | 特定品牌名称 |
| 找附近的咖啡店 |
categorysearch_tool | 通用类别,复数形式 |
| 37.7749, -122.4194是什么地方? | reverse
geocodetool | 坐标转地址 |
| 帝国大厦 | search
andgeocode_tool | 特定命名兴趣点 |
| 西雅图市中心的酒店 | category
searchtool | 通用类型+位置 |
| 塔吉特门店位置 | search
andgeocode_tool | 品牌名称(即使是复数) |
| 我附近的任何餐厅 | category
searchtool | 通用+任何短语 |
| 马萨诸塞州波士顿主街123号 | search
andgeocode_tool | 特定地址 |
| 电动车充电桩 | category
searchtool | 行业类别 |
| 麦当劳 | search
andgeocode_tool | 品牌名称 |
参数指南
Proximity(邻近度)vs Bbox(边界框)vs Country(国家)
三种空间约束搜索结果的方式:
1. proximity(强烈推荐)
作用: 使结果偏向某个位置,但不排除远处的匹配项
使用场景:
- - 用户说在我附近、附近、靠近
- 有参考点但希望有一定灵活性
- 希望结果按与某点的相关性排序
示例:
json
{
q: 披萨,
proximity: {
longitude: -122.4194,
latitude: 37.7749
}
}
为何有效: API会优先返回旧金山的披萨店,但如果高度相关,也可能包含著名的纽约披萨店
关键点: 有参考位置时务必设置proximity!否则结果基于IP或全局。
2. bbox(边界框)
作用: 硬性约束——仅返回框内的结果
使用场景:
- - 用户指定区域:在市中心、在这个街区
- 有定义的服务区域
- 需要确保结果在边界内
示例:
json
{
q: 酒店,
bbox: [-122.51, 37.7, -122.35, 37.83] // [最小经度, 最小纬度, 最大经度, 最大纬度]
}
为何有效: 确保所有酒店都在旧金山市中心区域内
注意事项: 框太小=无结果;框太大=不相关结果
3. country(国家)
作用: 将结果限制在特定国家
使用场景:
- - 用户指定国家:法国的餐厅
- 构建国家特定功能
- 需要尊重区域边界
- 或者明确用户希望结果在特定国家内
示例:
json
{
q: 巴黎,
country: [FR] // ISO 3166 alpha-2代码
}
为何有效: 找到法国巴黎(而非德克萨斯州巴黎)
可组合使用: proximity + country + bbox 或任意三者组合
决策矩阵:空间过滤器
| 场景 | 使用 | 原因 |
|---|
| 在我附近找咖啡 | proximity | 偏向用户位置 |
| 西雅图市中心的咖啡店 |
proximity + bbox | 以市中心为中心,限制区域 |
| 法国的酒店 | country | 硬性国家边界 |
| 旧金山最好的披萨 | proximity + country [US] | 偏向旧金山,限制在美国 |
| 这条路线上的加油站 | bbox around route | 路线走廊的硬性约束 |
| 5英里内的餐厅 | proximity(然后按距离过滤) | 偏向附近,过滤结果 |
设置limit参数
仅categorysearchtool适用(1-25,默认10)
| 使用场景 | 限制值 | 理由 |
|---|
| 快速建议 | 5 | 快速、聚焦的结果 |
| 标准列表 |
10 | 默认,良好平衡 |
| 全面搜索 | 25 | 允许的最大值 |
| 地图可视化 | 25 | 显示所有附近选项 |
| 下拉/自动补全 | 5 | 不使界面过载 |
性能提示: 限制值越低=响应越快
types参数(searchandgeocode_tool)
按要素类型过滤:
| 类型 | 包含内容 | 使用场景 |
|---|
| poi | 兴趣点(商家、地标) | 寻找兴趣点,非地址 |
| address |
街道地址 | 需要特定地址 |
| place | 城市、社区、区域 | 寻找区域/地区 |
| street | 不带门牌号的街道名称 | 需要街道,非特定地址 |
| postcode | 邮政编码 | 按邮政编码搜索 |
| district | 区、社区 | 基于区域的搜索 |
| locality | 城镇、村庄 | 市政搜索 |
| country | 国家名称 | 国家级别搜索 |
示例组合:
json
// 仅兴趣点和地址,不包含城市
{q: 巴黎, types: [poi, address]}
// 返回巴黎酒店、巴黎街,而非法国巴黎
// 仅地点(城市)
{q: 巴黎, types: [place]}
// 返回法国巴黎、德克萨斯州巴黎等
默认行为: 包含所有类型(通常符合需求)
autocomplete参数(searchandgeocodetool)
作用: 启用部分/模糊匹配
| 设置 | 行为 | 使用场景 |
|---|
| true | 匹配部分单词、拼写错误 | 用户实时输入 |
| false(默认) |
精确匹配 | 最终查询,非自动补全 |
示例:
json
// 用户输入starb
{ q: starb, auto_complete: true }
// 返回:星巴克、星条旗酒馆等
用途:
- - 即输即搜界面
- 处理拼写错误(mcdonalds -> 麦当劳)
- 不完整查询
不适用于:
应避免的反模式
不要:对品牌使用category_search
javascript
// 错误
categorysearchtool({ category: starbucks });
// starbucks不是类别,返回错误
// 正确
searchandgeocode_tool({ q: Starbucks });
不要:对通用类别使用searchandgeocode
javascript