maps_geo
Convert structured addresses and landmark names into precise latitude-longitude coordinates for location-based applications.
Instructions
将详细的结构化地址转换为经纬度坐标。支持对地标性名胜景区、建筑物名称解析为经纬度坐标
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | ||
| city | No |
Implementation Reference
- amap_mcp_server/server.py:44-82 (handler)The handler function for the 'maps_geo' tool. It takes an address and optional city, calls the Amap geocoding API to convert the address to coordinates and other location details, and returns the parsed results or an error.@mcp.tool() def maps_geo(address: str, city: Optional[str] = None) -> Dict[str, Any]: """将详细的结构化地址转换为经纬度坐标。支持对地标性名胜景区、建筑物名称解析为经纬度坐标""" try: params = { "key": AMAP_MAPS_API_KEY, "address": address } if city: params["city"] = city response = requests.get( "https://restapi.amap.com/v3/geocode/geo", params=params ) response.raise_for_status() data = response.json() if data["status"] != "1": return {"error": f"Geocoding failed: {data.get('info') or data.get('infocode')}"} geocodes = data.get("geocodes", []) results = [] for geo in geocodes: results.append({ "country": geo.get("country"), "province": geo.get("province"), "city": geo.get("city"), "citycode": geo.get("citycode"), "district": geo.get("district"), "street": geo.get("street"), "number": geo.get("number"), "adcode": geo.get("adcode"), "location": geo.get("location"), "level": geo.get("level") }) return {"return": results} except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"}