用于与 Google Maps 服务交互的工具,包括地点搜索、路线、地理编码等更多功能
GoogleMapTools 使 Agent 能够与各种 Google Maps 服务进行交互,以执行基于位置的操作,包括地点搜索、路线、地理编码等更多功能。
以下示例需要 googlemaps
库和一个 API 密钥,可以通过 Google Cloud Console 获取。
您需要在 Google Cloud Console 中启用以下 API:
Google Maps 工具的基本用法:
更多示例,请参阅 Google Maps Tools 示例。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
key | Optional[str] | None | 可选的 API 密钥。如果未提供,则使用 GOOGLE_MAPS_API_KEY 环境变量 |
search_places | bool | True | 启用地点搜索功能 |
get_directions | bool | True | 启用路线功能 |
validate_address | bool | True | 启用地址验证功能 |
geocode_address | bool | True | 启用地理编码功能 |
reverse_geocode | bool | True | 启用反向地理编码功能 |
get_distance_matrix | bool | True | 启用距离矩阵功能 |
get_elevation | bool | True | 启用海拔功能 |
get_timezone | bool | True | 启用时区功能 |
函数 | 描述 |
---|---|
search_places | 使用 Google Maps Places API 搜索地点。参数:query (str) 用于搜索查询。返回字符串化的 JSON,包含地点详情,如名称、地址、电话、网站、评分和营业时间。 |
get_directions | 获取地点之间的路线。参数:origin (str),destination (str),可选 mode (str) 用于出行方式,可选 avoid (List[str]) 用于需要避开的设施。返回路线信息。 |
validate_address | 验证地址。参数:address (str),可选 region_code (str),可选 locality (str)。返回地址验证结果。 |
geocode_address | 将地址转换为坐标。参数:address (str),可选 region (str)。返回包含坐标的位置信息。 |
reverse_geocode | 将坐标转换为地址。参数:lat (float),lng (float),可选 result_type 和 location_type (List[str])。返回地址信息。 |
get_distance_matrix | 计算地点之间的距离。参数:origins (List[str]),destinations (List[str]),可选 mode (str) 和 avoid (List[str])。返回距离和时长矩阵。 |
get_elevation | 获取某个地点的高程。参数:lat (float),lng (float)。返回高程数据。 |
get_timezone | 获取某个地点的时间区。参数:lat (float),lng (float),可选 timestamp (datetime)。返回时区信息。 |
Google Maps API 有使用限制和配额,具体取决于服务和账单计划。请参阅 Google Maps Platform 定价获取详细信息。