Skip to main content
Glama
masx200

AMap Maps MCP Server

by masx200

maps_distance

Calculate distances between locations using AMap Maps API. Measure driving, walking, or straight-line distances between coordinates to plan routes and analyze travel requirements.

Instructions

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

Input Schema

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

Implementation Reference

  • The core handler function for the 'maps_distance' tool. It constructs the Amap distance API request using the provided origins, destination, and type parameters, fetches the data, and returns formatted results or an error.
    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, };
  • Defines the input schema, name, and description for the 'maps_distance' tool, including parameters origins, destination, and optional type.
    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:848-850 (registration)
    Registers the tool by including it in the MAPS_TOOLS array returned by the ListTools request handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: MAPS_TOOLS, }));
  • build/index.js:890-893 (registration)
    Dispatches calls to the 'maps_distance' tool handler in the CallToolRequestSchema handler.
    case "maps_distance": { const { origins, destination, type } = request.params.arguments; return await handleDistance(origins, destination, type); }
  • build/index.js:247-260 (registration)
    Includes DISTANCE_TOOL in the array of all tools provided to the MCP server.
    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, ];

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