> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Maps

> 用于与 Google Maps 服务交互的工具，包括地点搜索、路线、地理编码等更多功能

**GoogleMapTools** 使 Agent 能够与各种 Google Maps 服务进行交互，以执行基于位置的操作，包括地点搜索、路线、地理编码等更多功能。

## 先决条件

以下示例需要 `googlemaps` 库和一个 API 密钥，可以通过 [Google Cloud Console](https://console.cloud.google.com/projectselector2/google/maps-apis/credentials) 获取。

```shell theme={null}
pip install googlemaps
```

```shell theme={null}
export GOOGLE_MAPS_API_KEY=your_api_key_here
```

您需要在 Google Cloud Console 中启用以下 API：

* Places API
* Directions API
* Geocoding API
* Address Validation API
* Distance Matrix API
* Elevation API
* Time Zone API

## 示例

Google Maps 工具的基本用法：

```python theme={null}
from agno.agent import Agent
from agno.tools.google_maps import GoogleMapTools

agent = Agent(tools=[GoogleMapTools()], show_tool_calls=True)
agent.print_response("Find coffee shops in San Francisco")
```

更多示例，请参阅 [Google Maps Tools 示例](/examples/concepts/tools/others/google_maps)。

## 工具箱参数

| 参数                    | 类型              | 默认值    | 描述                                               |
| --------------------- | --------------- | ------ | ------------------------------------------------ |
| `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 定价](https://cloud.google.com/maps-platform/pricing)获取详细信息。

## 开发者资源

* 查看 [工具](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/google_maps.py)
* 查看 [食谱](https://github.com/agno-agi/agno/blob/main/cookbook/tools/google_maps_tools.py)
