Skip to main content
Glama
cablate

MCP Google Map Server

maps_distance_matrix

Calculate travel distances and times between multiple origins and destinations using driving, walking, bicycling, or transit modes for efficient route planning.

Instructions

計算多個起點和終點之間的距離和時間

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
destinationsYes終點地址或座標列表
modeNo交通模式driving
originsYes起點地址或座標列表

Implementation Reference

  • The ACTION function implements the core logic of the 'maps_distance_matrix' tool. It creates a PlacesSearcher instance, calls calculateDistanceMatrix with the provided origins, destinations, and mode, and returns the formatted result or error.
    async function ACTION(params: any): Promise<{ content: any[]; isError?: boolean }> { try { // Create a new PlacesSearcher instance with the current request's API key const apiKey = getCurrentApiKey(); const placesSearcher = new PlacesSearcher(apiKey); const result = await placesSearcher.calculateDistanceMatrix(params.origins, params.destinations, params.mode); if (!result.success) { return { content: [{ type: "text", text: result.error || "Failed to calculate distance matrix" }], isError: true, }; } return { content: [ { type: "text", text: JSON.stringify(result.data, null, 2), }, ], isError: false, }; } catch (error: any) { const errorMessage = error instanceof Error ? error.message : JSON.stringify(error); return { isError: true, content: [{ type: "text", text: `Error calculating distance matrix: ${errorMessage}` }], }; } }
  • Zod schema defining the input parameters for the tool: origins (array of strings), destinations (array of strings), and mode (enum with default 'driving').
    const SCHEMA = { origins: z.array(z.string()).describe("List of origin addresses or coordinates"), destinations: z.array(z.string()).describe("List of destination addresses or coordinates"), mode: z.enum(["driving", "walking", "bicycling", "transit"]).default("driving").describe("Travel mode for calculation"), };
  • src/config.ts:47-52 (registration)
    Tool registration in the server configuration, importing and defining the tool using NAME, DESCRIPTION, SCHEMA, and ACTION from DistanceMatrix export.
    { name: DistanceMatrix.NAME, description: DistanceMatrix.DESCRIPTION, schema: DistanceMatrix.SCHEMA, action: (params: DistanceMatrixParams) => DistanceMatrix.ACTION(params), },
  • Supporting method in PlacesSearcher class that wraps the low-level Google Maps distance matrix call and handles errors.
    async calculateDistanceMatrix(origins: string[], destinations: string[], mode: "driving" | "walking" | "bicycling" | "transit" = "driving"): Promise<DistanceMatrixResponse> { try { const result = await this.mapsTools.calculateDistanceMatrix(origins, destinations, mode); return { success: true, data: result, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : "An error occurred while calculating distance matrix", }; } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cablate/mcp-google-map'

If you have feedback or need assistance with the MCP directory API, please join our Discord server