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

# Google路线集成

> 使用LangChain JavaScript集成Google路线工具。

Google路线工具允许您的智能体利用Google路线API来查找两个或多个目的地之间的路线。您可以获取步行、公共交通、汽车、摩托车和自行车的路线。

## 设置

您需要从[Google此处](https://developers.google.com/maps/documentation/places/web-service/overview)获取API密钥，并[启用路线API](https://console.cloud.google.com/apis/library/routes.googleapis.com)。然后，将您的API密钥设置为`process.env.GOOGLE_ROUTES_API_KEY`，或将其作为`apiKey`构造函数参数传入。

## 用法

<Tip>
  有关安装LangChain包的通用说明，请参见[此部分](/oss/javascript/langchain/install)。
</Tip>

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/openai @langchain/community @langchain/core
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { GoogleRoutesAPI } from "@langchain/community/tools/google_routes";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { ChatOpenAI } from "@langchain/openai";
import { AgentExecutor, createToolCallingAgent } from "@langchain/classic/agents";

export async function run() {
  const tools = [new GoogleRoutesAPI()];

  const llm = new ChatOpenAI({
    model: "gpt-3.5-turbo-0125",
  });

  const prompt = ChatPromptTemplate.fromMessages([
    ["system", "You are a helpful assistant"],
    ["placeholder", "{chat_history}"],
    ["human", "{input}"],
    ["placeholder", "{agent_scratchpad}"],
  ]);

  const agent = await createToolCallingAgent({
    llm,
    tools,
    prompt,
  });

  const agentExecutor = new AgentExecutor({
    agent,
    tools,
  });

  const result = await agentExecutor.invoke({
    input: "How to go from the Eiffel Tower to the Louvre Museum by transit?",
  });

  console.log(result);

  /* {
    input: 'How to go from the Eiffel Tower to the Louvre Museum by transit?',
    output: 'To travel from the Eiffel Tower to the Louvre Museum by transit, here is the route information:\n' +
      '\n' +
      '- Departure: Eiffel Tower\n' +
      '- Arrival: Louvre Museum\n' +
      '- Distance: 4.1 km\n' +
      '- Duration: 18 minutes\n' +
      '- Transit Fare: €2.15\n' +
      '\n' +
      'Travel Instructions:\n' +
      "1. Walk to Pont d'Iéna\n" +
      '2. Take bus 72 towards Gare de Lyon - Maison de La RATP\n' +
      '3. Walk to your destination\n' +
      '\n' +
      'Departure Time: 22:03\n' +
      'Arrival Time: 22:15\n' +
      '\n' +
      'Please follow these instructions to reach the Louvre Museum from the Eiffel Tower.'
  } */
}
```

## 相关内容

* 工具[概念指南](/oss/javascript/langchain/tools)
* 工具[操作指南](/oss/javascript/langchain/tools)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过MCP连接到Claude、VSCode等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在GitHub上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/tools/google_routes.mdx)或[提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
