maps_direction_transit_integrated_by_coordinates
Plan public transit routes using coordinates for trains, buses, and subways across cities, returning distance, duration, and detailed travel data.
Instructions
根据用户起终点经纬度坐标规划综合各类公共(火车、公交、地铁)交通方式的通勤方案,并且返回通勤方案的数据,跨城场景下必须传起点城市与终点城市
Args:
origin (str): 起点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909")
destination (str): 终点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909")
city (str): 起点城市名称
cityd (str): 终点城市名称
Returns:
Dict[str, Any]: 包含距离、时长和详细公共交通信息的路线数据
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| origin | Yes | ||
| destination | Yes | ||
| city | Yes | ||
| cityd | Yes |
Implementation Reference
- amap_mcp_server/server.py:536-633 (handler)The core handler function implementing the maps_direction_transit_integrated_by_coordinates tool. It is registered via the @mcp.tool() decorator and makes an API call to Amap's integrated transit direction service, parsing the response into a structured format with transit segments, bus lines, walking steps, etc.@mcp.tool() def maps_direction_transit_integrated_by_coordinates(origin: str, destination: str, city: str, cityd: str) -> Dict[str, Any]: """根据用户起终点经纬度坐标规划综合各类公共(火车、公交、地铁)交通方式的通勤方案,并且返回通勤方案的数据,跨城场景下必须传起点城市与终点城市 Args: origin (str): 起点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909") destination (str): 终点经纬度坐标,格式为"经度,纬度" (例如:"116.434307,39.90909") city (str): 起点城市名称 cityd (str): 终点城市名称 Returns: Dict[str, Any]: 包含距离、时长和详细公共交通信息的路线数据 """ try: response = requests.get( "https://restapi.amap.com/v3/direction/transit/integrated", params={ "key": AMAP_MAPS_API_KEY, "origin": origin, "destination": destination, "city": city, "cityd": cityd } ) response.raise_for_status() data = response.json() if data["status"] != "1": return {"error": f"Direction Transit Integrated failed: {data.get('info') or data.get('infocode')}"} transits = [] if data["route"].get("transits"): for transit in data["route"]["transits"]: segments = [] if transit.get("segments"): for segment in transit["segments"]: walking_steps = [] if segment.get("walking", {}).get("steps"): for step in segment["walking"]["steps"]: walking_steps.append({ "instruction": step.get("instruction"), "road": step.get("road"), "distance": step.get("distance"), "action": step.get("action"), "assistant_action": step.get("assistant_action") }) buslines = [] if segment.get("bus", {}).get("buslines"): for busline in segment["bus"]["buslines"]: via_stops = [] if busline.get("via_stops"): for stop in busline["via_stops"]: via_stops.append({"name": stop.get("name")}) buslines.append({ "name": busline.get("name"), "departure_stop": {"name": busline.get("departure_stop", {}).get("name")}, "arrival_stop": {"name": busline.get("arrival_stop", {}).get("name")}, "distance": busline.get("distance"), "duration": busline.get("duration"), "via_stops": via_stops }) segments.append({ "walking": { "origin": segment.get("walking", {}).get("origin"), "destination": segment.get("walking", {}).get("destination"), "distance": segment.get("walking", {}).get("distance"), "duration": segment.get("walking", {}).get("duration"), "steps": walking_steps }, "bus": {"buslines": buslines}, "entrance": {"name": segment.get("entrance", {}).get("name")}, "exit": {"name": segment.get("exit", {}).get("name")}, "railway": { "name": segment.get("railway", {}).get("name"), "trip": segment.get("railway", {}).get("trip") } }) transits.append({ "duration": transit.get("duration"), "walking_distance": transit.get("walking_distance"), "segments": segments }) return { "route": { "origin": data["route"]["origin"], "destination": data["route"]["destination"], "distance": data["route"].get("distance"), "transits": transits } } except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"}