mapbox-search-patterns

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Mapbox Search Patterns Skill

Mapbox搜索模式技能

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.
为AI助手提供有效使用Mapbox搜索工具的专业指导,涵盖工具选择、参数优化,以及地理编码、POI搜索和位置查找的最佳实践。

Available Search Tools

可用的搜索工具

1. search_and_geocode_tool

1. search_and_geocode_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")
最适用于: 特定地点、地址、品牌、命名位置
适用场景(查询包含以下内容时):
  • 具体名称:"第五大道的星巴克"、"帝国大厦"
  • 品牌名称:"麦当劳"、"全食超市"
  • 地址:"西雅图主街123号"、"时代广场1号"
  • 连锁店铺:"塔吉特"
  • 城市/地点:"旧金山"、"波特兰"
不适用于: 通用类别(如"咖啡店"、"博物馆")

2. category_search_tool

2. category_search_tool

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. reverse_geocode_tool

3. reverse_geocode_tool

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
最适用于: 将坐标转换为地址、城市、城镇、邮政编码
适用场景:
  • 拥有GPS坐标,需要可读的地址
  • 需要识别特定位置的场所
  • 将用户位置转换为地址

Tool Selection Decision Matrix

工具选择决策矩阵

User QueryToolReasoning
"Find Starbucks on Main Street"search_and_geocode_toolSpecific brand name
"Find coffee shops nearby"category_search_toolGeneric category, plural
"What's at 37.7749, -122.4194?"reverse_geocode_toolCoordinates to address
"Empire State Building"search_and_geocode_toolSpecific named POI
"hotels in downtown Seattle"category_search_toolGeneric type + location
"Target store locations"search_and_geocode_toolBrand name (even plural)
"any restaurant near me"category_search_toolGeneric + "any" phrase
"123 Main St, Boston, MA"search_and_geocode_toolSpecific address
"electric vehicle chargers"category_search_toolIndustry category
"McDonald's"search_and_geocode_toolBrand name
用户查询工具理由
"找到主街上的星巴克"search_and_geocode_tool包含具体品牌名称
"找到附近的咖啡店"category_search_tool通用类别、复数形式
"坐标37.7749, -122.4194是什么位置?"reverse_geocode_tool坐标转地址需求
"帝国大厦"search_and_geocode_tool具体命名POI
"西雅图市中心的酒店"category_search_tool通用类型+位置限定
"塔吉特门店位置"search_and_geocode_tool品牌名称(即使是复数)
"我附近的任意餐厅"category_search_tool通用类别+"任意"短语
"马萨诸塞州波士顿主街123号"search_and_geocode_tool具体地址
"电动汽车充电桩"category_search_tool行业类别
"麦当劳"search_and_geocode_tool品牌名称

Parameter Guidance

参数指导

Proximity vs Bbox vs Country

Proximity(邻近度)vs Bbox(边界框)vs Country(国家)

Three ways to spatially constrain search results:
三种空间约束搜索结果的方式:

1. proximity (STRONGLY RECOMMENDED)

1. proximity(强烈推荐)

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:
json
{
  "q": "pizza",
  "proximity": {
    "longitude": -122.4194,
    "latitude": 37.7749
  }
}
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.
作用: 使结果偏向某个位置,但不排除远距离匹配项
适用场景:
  • 用户提及"我附近"、"附近"、"靠近"
  • 有参考点但需要一定灵活性
  • 希望结果按与参考点的相关性排序
示例:
json
{
  "q": "pizza",
  "proximity": {
    "longitude": -122.4194,
    "latitude": 37.7749
  }
}
优势: API会优先返回旧金山的披萨店,但如果纽约的著名披萨店相关性极高,也会被包含在内
⚠️ 关键提示: 只要有参考位置,务必设置proximity!否则结果会基于IP或全球范围返回。

2. bbox (Bounding Box)

2. bbox(边界框)

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:
json
{
  "q": "hotel",
  "bbox": [-122.51, 37.7, -122.35, 37.83] // [minLon, minLat, maxLon, maxLat]
}
Why this works: Guarantees all hotels are within SF's downtown area
⚠️ Watch out: Too small = no results; too large = irrelevant results
作用: 硬约束 - 仅返回边界框内的结果
适用场景:
  • 用户指定区域:"市中心内"、"这个社区范围内"
  • 有明确的服务区域
  • 需要确保结果完全在指定范围内
示例:
json
{
  "q": "hotel",
  "bbox": [-122.51, 37.7, -122.35, 37.83] // [最小经度, 最小纬度, 最大经度, 最大纬度]
}
优势: 确保所有酒店都位于旧金山的市中心区域内
⚠️ 注意事项: 范围过小=无结果;范围过大=无关结果

3. country

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:
json
{
  "q": "Paris",
  "country": ["FR"] // ISO 3166 alpha-2 codes
}
Why this works: Finds Paris, France (not Paris, Texas)
Can combine:
proximity
+
country
+
bbox
or any combination of the three
作用: 将结果限制在特定国家
适用场景:
  • 用户指定国家:"法国的餐厅"
  • 开发针对特定国家的功能
  • 需要遵守区域边界
  • 或明确需要特定国家内的结果
示例:
json
{
  "q": "Paris",
  "country": ["FR"] // ISO 3166 alpha-2 国家代码
}
优势: 定位到法国巴黎(而非美国得克萨斯州的巴黎)
组合使用:
proximity
+
country
+
bbox
或三者任意组合

Decision Matrix: Spatial Filters

空间过滤器决策矩阵

ScenarioUseWhy
"Find coffee near me"proximityBias toward user location
"Coffee shops in downtown Seattle"proximity + bboxCenter on downtown, limit to area
"Hotels in France"countryHard country boundary
"Best pizza in San Francisco"proximity + country ["US"]Bias to SF, limit to US
"Gas stations along this route"bbox around routeHard constraint to route corridor
"Restaurants within 5 miles"proximity (then filter by distance)Bias nearby, filter results
场景使用方式理由
"找到我附近的咖啡店"proximity结果偏向用户位置
"西雅图市中心的咖啡店"proximity + bbox以市中心为中心,限制区域范围
"法国的酒店"country硬国家边界约束
"旧金山最好的披萨店"proximity + country ["US"]偏向旧金山,限制在美国范围内
"这条路线上的加油站"路线周边的bbox硬约束到路线走廊
"5英里范围内的餐厅"proximity(之后按距离过滤)偏向附近,再过滤结果

Setting limit Parameter

设置limit参数

category_search_tool only (1-25, default 10)
Use CaseLimitReasoning
Quick suggestions5Fast, focused results
Standard list10Default, good balance
Comprehensive search25Maximum allowed
Map visualization25Show all nearby options
Dropdown/autocomplete5Don't overwhelm UI
Performance tip: Lower limits = faster responses
仅适用于category_search_tool(取值1-25,默认10)
使用场景取值理由
快速建议5快速、聚焦的结果
标准列表10默认值,平衡效果好
全面搜索25允许的最大值
地图可视化25展示所有附近选项
下拉框/自动补全5避免界面信息过载
性能提示: 取值越小,响应速度越快

types Parameter (search_and_geocode_tool)

types参数(search_and_geocode_tool)

Filter by feature type:
TypeWhat It IncludesUse When
poi
Points of interest (businesses, landmarks)Looking for POIs, not addresses
address
Street addressesNeed specific address
place
Cities, neighborhoods, regionsLooking for area/region
street
Street names without numbersNeed street, not specific address
postcode
Postal codesSearching by ZIP/postal code
district
Districts, neighborhoodsArea-based search
locality
Towns, villagesMunicipality search
country
Country namesCountry-level search
Example combinations:
json
// Only POIs and addresses, no cities
{"q": "Paris", "types": ["poi", "address"]}
// Returns Paris Hotel, Paris Street, not Paris, France

// Only places (cities/regions)
{"q": "Paris", "types": ["place"]}
// Returns Paris, France; Paris, Texas; etc.
Default behavior: All types included (usually what you want)
按要素类型过滤:
类型包含内容适用场景
poi
兴趣点(企业、地标)查找POI,而非地址
address
街道地址需要具体地址
place
城市、社区、区域查找区域/地域
street
不含门牌号的街道名称需要街道,而非具体地址
postcode
邮政编码按邮编搜索
district
行政区、社区基于区域的搜索
locality
城镇、村庄市政区域搜索
country
国家名称国家层面搜索
组合示例:
json
// 仅包含POI和地址,排除城市
{"q": "Paris", "types": ["poi", "address"]}
// 返回巴黎酒店、巴黎街,而非法国巴黎

// 仅包含地点(城市/区域)
{"q": "Paris", "types": ["place"]}
// 返回法国巴黎、美国得克萨斯州巴黎等
默认行为: 包含所有类型(通常是最佳选择)

poi_category Parameter

poi_category参数

search_and_geocode_tool: Narrow generic searches
json
{
  "q": "lunch",
  "poi_category": ["restaurant", "cafe"],
  "proximity": { "longitude": -122.4194, "latitude": 37.7749 }
}
When to use:
  • Generic query that could match multiple categories
  • Want to focus search within category
  • User specifies type implicitly
category_search_tool: Use
poi_category_exclusions
instead
json
{
  "category": "food_and_drink",
  "poi_category_exclusions": ["bar", "nightclub"]
}
When to use:
  • Broad category but want to exclude subcategories
  • "Restaurants but not fast food"
search_and_geocode_tool: 缩小通用搜索范围
json
{
  "q": "lunch",
  "poi_category": ["restaurant", "cafe"],
  "proximity": { "longitude": -122.4194, "latitude": 37.7749 }
}
适用场景:
  • 通用查询可能匹配多个类别
  • 希望将搜索聚焦在特定类别内
  • 用户隐含指定类型
category_search_tool: 改用
poi_category_exclusions
json
{
  "category": "food_and_drink",
  "poi_category_exclusions": ["bar", "nightclub"]
}
适用场景:
  • 宽泛类别但需要排除子类别
  • "餐厅但不包括快餐店"

auto_complete Parameter (search_and_geocode_tool)

auto_complete参数(search_and_geocode_tool)

What it does: Enables partial/fuzzy matching
SettingBehaviorUse When
true
Matches partial words, typosUser typing in real-time
false
(default)
Exact matchingFinal query, not autocomplete
Example:
<!-- cspell:disable -->
json
// User types "starb"
{ "q": "starb", "auto_complete": true }
// Returns: Starbucks, Starboard Tavern, etc.
Use for:
  • Search-as-you-type interfaces
  • Handling typos ("mcdonalds" → McDonald's)
<!-- cspell:enable -->
  • Incomplete queries
Don't use for:
  • Final/submitted queries (less precise)
  • When you need exact matches
作用: 启用部分/模糊匹配
设置值行为适用场景
true
匹配部分单词、拼写错误用户实时输入时
false
(默认)
精确匹配最终提交的查询,非自动补全场景
示例:
<!-- cspell:disable -->
json
// 用户输入"starb"
{ "q": "starb", "auto_complete": true }
// 返回:Starbucks, Starboard Tavern等
适用场景:
  • 边输入边搜索的界面
  • 处理拼写错误("mcdonalds" → McDonald's)
<!-- cspell:enable -->
  • 不完整的查询
不适用场景:
  • 最终提交的查询(精度较低)
  • 需要精确匹配的场景

ETA Parameters (search_and_geocode_tool)

ETA参数(search_and_geocode_tool)

Request estimated time of arrival to results
Parameters:
  • eta_type
    : Set to
    "navigation"
  • navigation_profile
    :
    "driving"
    |
    "walking"
    |
    "cycling"
  • origin
    : Starting coordinates
Use when:
  • User asks "how long to get there?"
  • Sorting by travel time, not distance
  • Need route time, not straight-line distance
Example:
json
{
  "q": "grocery stores",
  "proximity": { "longitude": -122.4194, "latitude": 37.7749 },
  "eta_type": "navigation",
  "navigation_profile": "driving",
  "origin": { "longitude": -122.4194, "latitude": 37.7749 }
}
Returns: Results with
eta
(travel time in seconds)
⚠️ Cost: Requires routing calculation per result (counts toward API quota)
When NOT to use:
  • Just need straight-line distance (use distance_tool offline after search)
  • Budget-conscious (adds API cost)
请求结果的预计到达时间
参数:
  • eta_type
    : 设置为
    "navigation"
  • navigation_profile
    :
    "driving"
    |
    "walking"
    |
    "cycling"
  • origin
    : 起始坐标
适用场景:
  • 用户询问"到那里需要多久?"
  • 按行程时间而非距离排序
  • 需要路线时间,而非直线距离
示例:
json
{
  "q": "grocery stores",
  "proximity": { "longitude": -122.4194, "latitude": 37.7749 },
  "eta_type": "navigation",
  "navigation_profile": "driving",
  "origin": { "longitude": -122.4194, "latitude": 37.7749 }
}
返回: 包含
eta
(行程时间,单位秒)的结果
⚠️ 成本提示: 每个结果都需要路由计算(会占用API配额)
不适用场景:
  • 仅需要直线距离(搜索后使用离线distance_tool)
  • 关注成本预算(会增加API费用)

format Parameter (category_search_tool)

format参数(category_search_tool)

Choose output format:
FormatReturnsUse When
formatted_text
(default)
Human-readable textDisplaying to user directly
json_string
GeoJSON as JSON stringNeed to parse/process results
Example:
formatted_text:
1. Blue Bottle Coffee
   Address: 66 Mint St, San Francisco, CA
   Coordinates: 37.7825, -122.4052
   Type: poi
json_string:
json
{
  "type": "FeatureCollection",
  "features": [{
    "type": "Feature",
    "geometry": {"type": "Point", "coordinates": [-122.4052, 37.7825]},
    "properties": {"name": "Blue Bottle Coffee", ...}
  }]
}
Decision:
  • Showing list to user →
    formatted_text
  • Plotting on map →
    json_string
    (parse and use coordinates)
  • Further processing →
    json_string
选择输出格式:
格式返回内容适用场景
formatted_text
(默认)
人类可读文本直接展示给用户
json_string
以JSON字符串形式返回GeoJSON需要解析/处理结果
示例:
formatted_text:
1. Blue Bottle Coffee
   地址:66 Mint St, San Francisco, CA
   坐标:37.7825, -122.4052
   类型:poi
json_string:
json
{
  "type": "FeatureCollection",
  "features": [{
    "type": "Feature",
    "geometry": {"type": "Point", "coordinates": [-122.4052, 37.7825]},
    "properties": {"name": "Blue Bottle Coffee", ...}
  }]
}
决策建议:
  • 向用户展示列表 →
    formatted_text
  • 在地图上绘制 →
    json_string
    (解析后使用坐标)
  • 进一步处理 →
    json_string

language Parameter

language参数

ISO language codes (e.g., "en", "es", "fr", "de", "ja", "zh")
Use when:
  • Building multilingual app
  • User's language preference known
  • Need localized names
Example:
json
{
  "q": "東京タワー",
  "language": "ja"
}
// Returns results in Japanese
Default: English (if not specified)
Tip: Match user's locale for best experience
ISO语言代码(例如:"en", "es", "fr", "de", "ja", "zh")
适用场景:
  • 开发多语言应用
  • 已知用户语言偏好
  • 需要本地化名称
示例:
json
{
  "q": "東京タワー",
  "language": "ja"
}
// 返回日语结果
默认值: 英语(未指定时)
提示: 匹配用户的区域设置以获得最佳体验

Common Patterns and Workflows

常见模式与工作流

Pattern 1: "Near Me" Search

模式1:"我附近"搜索

User: "Find coffee shops near me"
Optimal approach:
1. Get user's location (from app/browser)
2. Use category_search_tool:
   - category: "coffee_shop"
   - proximity: user's coordinates
   - limit: 10
Why: Category tool for generic "coffee shops", proximity for "near me"
用户: "找到我附近的咖啡店"
最优方案:
1. 获取用户位置(从应用/浏览器)
2. 使用category_search_tool:
   - category: "coffee_shop"
   - proximity: 用户坐标
   - limit: 10
理由: 通用"咖啡店"使用类别工具,proximity处理"我附近"

Pattern 2: Branded Chain Lookup

模式2:品牌连锁店查找

User: "Find all Starbucks in Seattle"
Optimal approach:
1. Use search_and_geocode_tool:
   - q: "Starbucks"
   - proximity: Seattle coordinates
   - country: ["US"]
2. Or if need strict boundary:
   - bbox: Seattle city bounds
Why: Brand name = search_and_geocode_tool; proximity biases to Seattle
用户: "找到西雅图所有的星巴克"
最优方案:
1. 使用search_and_geocode_tool:
   - q: "Starbucks"
   - proximity: 西雅图坐标
   - country: ["US"]
2. 如果需要严格边界:
   - bbox: 西雅图城市边界
理由: 品牌名称使用search_and_geocode_tool;proximity使结果偏向西雅图

Pattern 3: Address Geocoding

模式3:地址地理编码

User: "What are the coordinates of 1600 Pennsylvania Ave?"
Optimal approach:
Use search_and_geocode_tool:
- q: "1600 Pennsylvania Ave, Washington DC"
- types: ["address"]  // Focus on addresses
- country: ["US"]     // Narrow to US
Why: Specific address with country context for disambiguation
用户: "宾夕法尼亚大道1600号的坐标是什么?"
最优方案:
使用search_and_geocode_tool:
- q: "1600 Pennsylvania Ave, Washington DC"
- types: ["address"]  // 聚焦地址
- country: ["US"]     // 缩小到美国范围
理由: 特定地址+国家上下文用于消歧义

Pattern 4: Category Search with Area Restriction

模式4:带区域限制的类别搜索

User: "Show me all hotels in downtown Portland"
Optimal approach:
1. Geocode "downtown Portland" → get center point
2. Define downtown bbox (or use 1-2 mile radius)
3. Use category_search_tool:
   - category: "hotel"
   - bbox: downtown bounds (or proximity + filter by distance)
   - limit: 25  // Get comprehensive list
Why: Category for "hotels", bbox for "in downtown" hard boundary
用户: "展示波特兰市中心的所有酒店"
最优方案:
1. 地理编码"波特兰市中心" → 获取中心点
2. 定义市中心的bbox(或使用1-2英里半径)
3. 使用category_search_tool:
   - category: "hotel"
   - bbox: 市中心边界(或proximity+按距离过滤)
   - limit: 25  // 获取全面列表
理由: "酒店"使用类别工具,bbox处理"市中心"硬边界

Pattern 5: Reverse Geocoding

模式5:反向地理编码

User: "What's at these GPS coordinates?"
Optimal approach:
Use reverse_geocode_tool:
- longitude: -122.4194
- latitude: 37.7749
- types: ["address"]  // Get address (can also use place, locality, postcode, etc.)
Why: Coordinates → address is exactly what reverse geocoding does
用户: "这些GPS坐标是什么位置?"
最优方案:
使用reverse_geocode_tool:
- longitude: -122.4194
- latitude: 37.7749
- types: ["address"]  // 获取地址(也可使用place、locality、postcode等)
理由: 坐标转地址正是反向地理编码的用途

Pattern 6: Route-Based Search

模式6:基于路线的搜索

User: "Find gas stations along my route"
Optimal approach:
1. Get route geometry from directions_tool
2. Create bbox around route (use bounding_box_tool)
3. Use category_search_tool:
   - category: "gas_station"
   - bbox: route bounding box
4. Filter results to those within X meters of route (use distance_tool)
Why: Bbox for rough filter, then distance calculation for precision
用户: "找到我路线上的加油站"
最优方案:
1. 从directions_tool获取路线几何信息
2. 围绕路线创建bbox(使用bounding_box_tool)
3. 使用category_search_tool:
   - category: "gas_station"
   - bbox: 路线边界框
4. 过滤出距离路线X米内的结果(使用distance_tool)
理由: bbox进行粗过滤,距离计算保证精度

Pattern 7: Multilingual POI Search

模式7:多语言POI搜索

User: "Find ramen shops" (user locale: ja)
Optimal approach:
Use category_search_tool:
- category: "ramen_restaurant" (or "restaurant")
- language: "ja"
- proximity: user location
Why: Returns Japanese names/addresses for better UX
用户: "找到拉面店"(用户区域设置:日语)
最优方案:
使用category_search_tool:
- category: "ramen_restaurant"(或"restaurant")
- language: "ja"
- proximity: 用户位置
理由: 返回日语名称/地址,提升用户体验

Anti-Patterns to Avoid

需避免的反模式

❌ Don't: Use category_search for brands

❌ 不要:对品牌使用category_search

javascript
// BAD
category_search_tool({ category: 'starbucks' });
// "starbucks" is not a category, returns error

// GOOD
search_and_geocode_tool({ q: 'Starbucks' });
javascript
// 错误
category_search_tool({ category: 'starbucks' });
// "starbucks"不是有效类别,返回错误

// 正确
search_and_geocode_tool({ q: 'Starbucks' });

❌ Don't: Use search_and_geocode for generic categories

❌ 不要:对通用类别使用search_and_geocode

javascript
// BAD
search_and_geocode_tool({ q: 'coffee shops' });
// Less precise, may return unrelated results

// GOOD
category_search_tool({ category: 'coffee_shop' });
javascript
// 错误
search_and_geocode_tool({ q: 'coffee shops' });
// 精度较低,可能返回无关结果

// 正确
category_search_tool({ category: 'coffee_shop' });

❌ Don't: Forget proximity for local searches

❌ 不要:本地搜索时忘记设置proximity

javascript
// BAD - Results may be anywhere globally
category_search_tool({ category: 'restaurant' });

// GOOD - Biased to user location
category_search_tool({
  category: 'restaurant',
  proximity: { longitude: -122.4194, latitude: 37.7749 }
});
javascript
// 错误 - 结果可能来自全球任意地方
category_search_tool({ category: 'restaurant' });

// 正确 - 结果偏向用户位置
category_search_tool({
  category: 'restaurant',
  proximity: { longitude: -122.4194, latitude: 37.7749 }
});

❌ Don't: Use bbox when you mean proximity

❌ 不要:需要proximity时使用bbox

javascript
// BAD - Hard boundary may exclude good nearby results
search_and_geocode_tool({
  q: 'pizza',
  bbox: [-122.42, 37.77, -122.41, 37.78] // Tiny box
});

// GOOD - Bias toward point, but flexible
search_and_geocode_tool({
  q: 'pizza',
  proximity: { longitude: -122.4194, latitude: 37.7749 }
});
javascript
// 错误 - 硬边界可能排除优质的附近结果
search_and_geocode_tool({
  q: 'pizza',
  bbox: [-122.42, 37.77, -122.41, 37.78] // 极小的范围
});

// 正确 - 偏向指定点,但保留灵活性
search_and_geocode_tool({
   q: 'pizza',
   proximity: { longitude: -122.4194, latitude: 37.7749 }
});

❌ Don't: Request ETA unnecessarily

❌ 不要:不必要地请求ETA

javascript
// BAD - Costs API quota for routing calculations
search_and_geocode_tool({
  q: 'museums',
  eta_type: 'navigation',
  navigation_profile: 'driving'
});
// User didn't ask for travel time!

// GOOD - Only add ETA when needed
search_and_geocode_tool({ q: 'museums' });
// If user asks "how long to get there?", then add ETA
javascript
// 错误 - 路由计算会占用API配额
search_and_geocode_tool({
  q: 'museums',
   eta_type: 'navigation',
   navigation_profile: 'driving'
});
// 用户并没有询问行程时间!

// 正确 - 仅在需要时添加ETA
search_and_geocode_tool({ q: 'museums' });
// 如果用户询问"到那里需要多久?",再添加ETA

❌ Don't: Set limit too high for UI display

❌ 不要:为界面显示设置过高的limit

javascript
// BAD - Overwhelming for simple dropdown
category_search_tool({
  category: 'restaurant',
  limit: 25
});
// Returns 25 restaurants for a 5-item dropdown

// GOOD - Match UI needs
category_search_tool({
  category: 'restaurant',
  limit: 5
});
javascript
// 错误 - 简单下拉框会信息过载
category_search_tool({
  category: 'restaurant',
  limit: 25
});
// 为5项的下拉框返回25家餐厅

// 正确 - 匹配界面需求
category_search_tool({
  category: 'restaurant',
  limit: 5
});

Performance Optimization

性能优化

Minimize API Calls

减少API调用

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
模式:地理编码一次,复用坐标
// 正确
1. 用户输入"西雅图"
2. 地理编码"西雅图" → (lng, lat)
3. 将这些坐标用于多次类别搜索
4. 在会话中缓存坐标

// 错误
1. 搜索咖啡店时地理编码"西雅图"
2. 搜索餐厅时再次地理编码"西雅图"
3. 搜索酒店时第三次地理编码"西雅图"

Set Appropriate Limits

设置合适的limit值

UI ContextRecommended Limit
Autocomplete dropdown5
List view10
Map view25
Export/download25 (or paginate)
界面场景推荐取值
自动补全下拉框5
列表视图10
地图视图25
导出/下载25(或分页)

Use Offline Tools When Possible

尽可能使用离线工具

After getting search results:
1. category_search_tool → Get POIs
2. distance_tool (offline) → Calculate distances
3. bearing_tool (offline) → Get directions
Why: Search once (API), then use offline tools for calculations (free, fast)
获取搜索结果后:
1. category_search_tool → 获取POI
2. distance_tool(离线)→ 计算距离
3. bearing_tool(离线)→ 获取方向
理由: 一次搜索(API),之后使用离线工具进行计算(免费、快速)

Combining Search with Other Tools

搜索与其他工具的结合

Search → Distance Calculation

搜索 → 距离计算

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 distance
1. category_search_tool({category: "hospital", proximity: user_location})
   → 返回10家带坐标的医院
2. distance_tool(user_location, each_hospital)
   → 离线计算精确距离
3. 按距离排序

Search → Directions

搜索 → 路线规划

1. search_and_geocode_tool({q: "Space Needle"})
   → Get destination coordinates
2. directions_tool({from: user_location, to: space_needle_coords})
   → Get turn-by-turn directions
1. search_and_geocode_tool({q: "Space Needle"})
   → 获取目的地坐标
2. directions_tool({from: user_location, to: space_needle_coords})
   → 获取逐向导航路线

Search → Isochrone → Containment Check

搜索 → 等时线 → 包含性检查

1. 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 zone
1. search_and_geocode_tool({q: "warehouse"})
   → 获取仓库坐标
2. isochrone_tool({coordinates: warehouse, time: 30, profile: "driving"})
   → 获取30分钟配送区域多边形
3. point_in_polygon_tool(customer_address, delivery_zone)
   → 检查客户是否在配送区域内

Search → Static Map Visualization

搜索 → 静态地图可视化

1. 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 restaurants
1. category_search_tool({category: "restaurant", limit: 10})
   → 获取餐厅坐标
2. static_map_image_tool({
     markers: restaurant_coordinates,
     auto_fit: true
   })
   → 创建展示所有餐厅的地图图片

Handling No Results

无结果处理

If category_search returns no results:

如果category_search返回无结果:

Possible reasons:
  1. Invalid category → Use
    resource_reader_tool
    with
    mapbox://categories
    to see valid categories
  2. Too restrictive bbox → Expand area or use proximity instead
  3. No POIs in area → Try broader category or remove spatial filters
  4. Wrong country filter → Check country codes
Example 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"}) → Success
可能原因:
  1. 无效类别 → 使用
    resource_reader_tool
    并传入
    mapbox://categories
    查看有效类别
  2. bbox过于严格 → 扩大区域或改用proximity
  3. 区域内无POI → 尝试更宽泛的类别或移除空间过滤器
  4. 国家过滤器错误 → 检查国家代码
示例恢复流程:
1. category_search_tool({category: "taco"}) → 无结果
2. 检查:"taco"是有效类别吗?
   → 使用category_list_tool → 发现"mexican_restaurant"是有效类别
3. 重试:category_search_tool({category: "mexican_restaurant"}) → 成功

If search_and_geocode returns no results:

如果search_and_geocode返回无结果:

Possible reasons:
  1. Typo in query → Retry with
    auto_complete: true
  2. Too specific → Broaden search (remove address numbers, try nearby city)
  3. Wrong types filter → Remove or expand types
  4. Not a recognized place → Check spelling, try alternative names
可能原因:
  1. 查询存在拼写错误 → 启用
    auto_complete: true
    重试
  2. 查询过于具体 → 放宽搜索条件(移除门牌号,尝试附近城市)
  3. types过滤器错误 → 移除或扩大types范围
  4. 未被识别的地点 → 检查拼写,尝试替代名称

Category List Resource

类别列表资源

Get 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:
  • User enters free-text category
  • Need to map user terms to Mapbox categories
  • Validating category before search
Example mapping:
  • User: "places to eat" → Category: "restaurant"
  • User: "gas" → Category: "gas_station"
  • User: "lodging" → Category: "hotel"
获取有效类别: 使用
resource_reader_tool
category_list_tool
resource_reader_tool({uri: "mapbox://categories"})
返回: 所有有效类别ID(例如:"restaurant", "hotel", "gas_station")
适用场景:
  • 用户输入自由文本类别
  • 需要将用户术语映射到Mapbox类别
  • 搜索前验证类别有效性
示例映射:
  • 用户:"吃饭的地方" → 类别:"restaurant"
  • 用户:"加油站" → 类别:"gas_station"
  • 用户:"住宿" → 类别:"hotel"

Quick Reference

快速参考

Tool Selection Flowchart

工具选择流程图

User query contains...

→ Specific name/brand (Starbucks, Empire State Building)
  → search_and_geocode_tool

→ Generic category/plural (coffee shops, museums, any restaurant)
  → category_search_tool

→ Coordinates → Address
  → reverse_geocode_tool

→ Address → Coordinates
  → search_and_geocode_tool with types: ["address"]
用户查询包含...

→ 具体名称/品牌(Starbucks, 帝国大厦)
  → search_and_geocode_tool

→ 通用类别/复数(咖啡店, 博物馆, 任意餐厅)
  → category_search_tool

→ 坐标 → 地址
  → reverse_geocode_tool

→ 地址 → 坐标
  → search_and_geocode_tool并设置types: ["address"]

Essential Parameters Checklist

核心参数检查清单

For local searches, ALWAYS set:
  • proximity
    (or bbox if strict boundary needed)
For category searches, consider:
  • limit
    (match UI needs)
  • format
    (json_string if plotting on map)
For disambiguation, use:
  • country
    (when geographic context matters)
  • types
    (when feature type matters)
For travel-time ranking:
  • eta_type
    ,
    navigation_profile
    ,
    origin
    (costs API quota)
本地搜索时,务必设置:
  • proximity
    (如果需要严格边界则用bbox)
类别搜索时,考虑设置:
  • limit
    (匹配界面需求)
  • format
    (如果要在地图上绘制则用json_string)
消歧义时,使用:
  • country
    (当地理上下文重要时)
  • types
    (当要素类型重要时)
按行程时间排序时:
  • eta_type
    ,
    navigation_profile
    ,
    origin
    (会占用API配额)

Common Mistakes

常见错误

  1. Forgetting proximity → Results are global/IP-based
  2. Using wrong tool → category_search for "Starbucks" (use search_and_geocode)
  3. Invalid category → Check category_list first
  4. Bbox too small → No results; use proximity instead
  5. Requesting ETA unnecessarily → Adds API cost
  6. Limit too high for UI → Overwhelming user
  7. Not filtering types → Get cities when you want POIs
  1. 忘记设置proximity → 结果可能来自全球任意地方
  2. 对品牌使用category_search → "starbucks"不是类别,返回错误
  3. 使用无效类别 → 搜索前先检查类别列表
  4. bbox范围过小 → 无结果;改用proximity
  5. 不必要地请求ETA → 增加API成本
  6. 为界面设置过高的limit → 导致用户界面信息过载
  7. 未过滤types → 想要POI时却得到城市结果

Integration with Other Skills

与其他技能的集成

Works with:
  • mapbox-geospatial-operations: After search, use offline distance/bearing calculations
  • mapbox-web-integration-patterns: Display search results on map in web app
  • mapbox-token-security: Ensure search requests use properly scoped tokens
可配合使用:
  • mapbox-geospatial-operations: 搜索后,使用离线距离/方向计算
  • mapbox-web-integration-patterns: 在Web应用中展示地图上的搜索结果
  • mapbox-token-security: 确保搜索请求使用权限正确的令牌

Resources

资源