maps_distance
Calculate distances between geographic coordinates for driving, walking, or straight-line routes using AMap Maps data.
Instructions
距离测量 API 可以测量两个经纬度坐标之间的距离,支持驾车、步行以及球面距离测量
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| origins | Yes | 起点经度,纬度,可以传多个坐标,使用竖线隔离,比如120,30|120,31,坐标格式为:经度,纬度 | |
| destination | Yes | 终点经度,纬度,坐标格式为:经度,纬度 | |
| type | No | 距离测量类型,1代表驾车距离测量,0代表直线距离测量,3步行距离测量 |
Implementation Reference
- build/index.js:704-742 (handler)The handler function that executes the maps_distance tool logic by calling the Amap distance measurement API and formatting the response.async function handleDistance(origins, destination, type = "1") { const url = new URL("https://restapi.amap.com/v3/distance"); url.searchParams.append("key", AMAP_MAPS_API_KEY); url.searchParams.append("origins", origins); url.searchParams.append("destination", destination); url.searchParams.append("type", type); url.searchParams.append("source", "ts_mcp"); const response = await fetch(url.toString()); const data = await response.json(); if (data.status !== "1") { return { content: [{ type: "text", text: `Direction Distance failed: ${data.info || data.infocode}`, }], isError: true, }; } return { content: [{ type: "text", text: JSON.stringify( { results: data.results.map((result) => { return { origin_id: result.origin_id, dest_id: result.dest_id, distance: result.distance, duration: result.duration, }; }), }, null, 2, ), }], isError: false, }; }
- build/index.js:163-187 (schema)Input schema and metadata definition for the maps_distance tool.const DISTANCE_TOOL = { name: "maps_distance", description: "距离测量 API 可以测量两个经纬度坐标之间的距离,支持驾车、步行以及球面距离测量", inputSchema: { type: "object", properties: { origins: { type: "string", description: "起点经度,纬度,可以传多个坐标,使用竖线隔离,比如120,30|120,31,坐标格式为:经度,纬度", }, destination: { type: "string", description: "终点经度,纬度,坐标格式为:经度,纬度", }, type: { type: "string", description: "距离测量类型,1代表驾车距离测量,0代表直线距离测量,3步行距离测量", }, }, required: ["origins", "destination"], }, };
- build/index.js:890-893 (registration)Registration of the maps_distance handler in the tool dispatch switch statement.case "maps_distance": { const { origins, destination, type } = request.params.arguments; return await handleDistance(origins, destination, type); }
- build/index.js:247-260 (registration)Inclusion of DISTANCE_TOOL in the list of available tools returned by listTools.const MAPS_TOOLS = [ REGEOCODE_TOOL, GEO_TOOL, IP_LOCATION_TOOL, WEATHER_TOOL, SEARCH_DETAIL_TOOL, BICYCLING_TOOL, WALKING_TOOL, DRIVING_TOOl, TRANSIT_INTEGRATED_TOOL, DISTANCE_TOOL, TEXT_SEARCH_TOOL, AROUND_SEARCH_TOOL, ];
- build/streamable-http.js:966-969 (handler)Handler dispatch for maps_distance in the HTTP version of the server.case "maps_distance": { const { origins, destination, type } = request.params.arguments; return await handleDistance(origins, destination, type); }