Skip to main content
Glama

maps_direction_driving_by_coordinates

Plan driving routes using latitude and longitude coordinates to calculate distance, travel time, and navigation details for car commutes between specified locations.

Instructions

驾车路径规划 API 可以根据用户起终点经纬度坐标规划以小客车、轿车通勤出行的方案,并且返回通勤方案的数据

Args: origin (str): 起点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909") destination (str): 终点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909") Returns: Dict[str, Any]: 包含距离、时长和详细导航信息的路线数据

Input Schema

NameRequiredDescriptionDefault
originYes
destinationYes

Input Schema (JSON Schema)

{ "properties": { "destination": { "title": "Destination", "type": "string" }, "origin": { "title": "Origin", "type": "string" } }, "required": [ "origin", "destination" ], "type": "object" }

Implementation Reference

  • The handler function decorated with @mcp.tool(), implementing driving directions from origin to destination coordinates using Amap API. Handles API request, parses response, extracts route paths and steps.
    @mcp.tool() def maps_direction_driving_by_coordinates(origin: str, destination: str) -> Dict[str, Any]: """驾车路径规划 API 可以根据用户起终点经纬度坐标规划以小客车、轿车通勤出行的方案,并且返回通勤方案的数据 Args: origin (str): 起点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909") destination (str): 终点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909") Returns: Dict[str, Any]: 包含距离、时长和详细导航信息的路线数据 """ try: response = requests.get( "https://restapi.amap.com/v3/direction/driving", params={ "key": AMAP_MAPS_API_KEY, "origin": origin, "destination": destination } ) response.raise_for_status() data = response.json() if data["status"] != "1": return {"error": f"Direction Driving failed: {data.get('info') or data.get('infocode')}"} paths = [] for path in data["route"]["paths"]: steps = [] for step in path["steps"]: steps.append({ "instruction": step.get("instruction"), "road": step.get("road"), "distance": step.get("distance"), "orientation": step.get("orientation"), "duration": step.get("duration") }) paths.append({ "path": path.get("path"), "distance": path.get("distance"), "duration": path.get("duration"), "steps": steps }) return { "route": { "origin": data["route"]["origin"], "destination": data["route"]["destination"], "paths": paths } } except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"}
  • The @mcp.tool() decorator registers the maps_direction_driving_by_coordinates function as an MCP tool.
    @mcp.tool()
  • Function signature and docstring define input parameters (origin, destination as str coordinates) and output as Dict with route information.
    def maps_direction_driving_by_coordinates(origin: str, destination: str) -> Dict[str, Any]: """驾车路径规划 API 可以根据用户起终点经纬度坐标规划以小客车、轿车通勤出行的方案,并且返回通勤方案的数据 Args: origin (str): 起点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909") destination (str): 终点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909") Returns: Dict[str, Any]: 包含距离、时长和详细导航信息的路线数据 """
  • Called as a helper by the maps_direction_driving_by_address tool after geocoding addresses to coordinates.
    route_result = maps_direction_driving_by_coordinates(origin_location, destination_location)

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

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