maps_distance
Calculate distance between coordinates using driving, walking, or spherical distance measurements for route planning and location analysis.
Instructions
测量两个经纬度坐标之间的距离,支持驾车、步行以及球面距离测量
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| origins | Yes | ||
| destination | Yes | ||
| type | No | 1 |
Input Schema (JSON Schema)
{
"properties": {
"destination": {
"title": "Destination",
"type": "string"
},
"origins": {
"title": "Origins",
"type": "string"
},
"type": {
"default": "1",
"title": "Type",
"type": "string"
}
},
"required": [
"origins",
"destination"
],
"type": "object"
}
Implementation Reference
- amap_mcp_server/server.py:634-664 (handler)The maps_distance tool handler: measures distance between origins and destination coordinates using Amap API, supports driving, walking, and spherical distance types. Registered via @mcp.tool() decorator.@mcp.tool() def maps_distance(origins: str, destination: str, type: str = "1") -> Dict[str, Any]: """测量两个经纬度坐标之间的距离,支持驾车、步行以及球面距离测量""" try: response = requests.get( "https://restapi.amap.com/v3/distance", params={ "key": AMAP_MAPS_API_KEY, "origins": origins, "destination": destination, "type": type } ) response.raise_for_status() data = response.json() if data["status"] != "1": return {"error": f"Direction Distance failed: {data.get('info') or data.get('infocode')}"} results = [] for result in data["results"]: results.append({ "origin_id": result.get("origin_id"), "dest_id": result.get("dest_id"), "distance": result.get("distance"), "duration": result.get("duration") }) return {"results": results} except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"}