Skip to main content
Glama
masx200

AMap Maps MCP Server

by masx200

maps_distance

Calculate distances between geographic coordinates for driving, walking, or straight-line routes using AMap Maps data.

Instructions

距离测量 API 可以测量两个经纬度坐标之间的距离,支持驾车、步行以及球面距离测量

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originsYes起点经度,纬度,可以传多个坐标,使用竖线隔离,比如120,30|120,31,坐标格式为:经度,纬度
destinationYes终点经度,纬度,坐标格式为:经度,纬度
typeNo距离测量类型,1代表驾车距离测量,0代表直线距离测量,3步行距离测量

Implementation Reference

  • 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, }; }
  • 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, ];
  • 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); }

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/masx200/amap-maps-mcp-server'

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