Skip to main content
Glama

maps_geo

Convert structured addresses and landmark names into precise latitude and longitude coordinates using geocoding technology.

Instructions

将详细的结构化地址转换为经纬度坐标。支持对地标性名胜景区、建筑物名称解析为经纬度坐标

Input Schema

NameRequiredDescriptionDefault
addressYes
cityNo

Input Schema (JSON Schema)

{ "properties": { "address": { "title": "Address", "type": "string" }, "city": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "City" } }, "required": [ "address" ], "type": "object" }

Implementation Reference

  • The maps_geo tool handler function decorated with @mcp.tool(), which performs geocoding by converting a structured address (with optional city) to latitude/longitude coordinates using the Amap Geocoding API (https://restapi.amap.com/v3/geocode/geo). Returns detailed geocoding results or 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)}"}
  • Registration of the maps_geo tool using the @mcp.tool() decorator from FastMCP.
    @mcp.tool()
  • Input schema defined by function signature: address (str, required), city (Optional[str]). Output: Dict[str, Any] with geocoding results.
    def maps_geo(address: str, city: Optional[str] = None) -> Dict[str, Any]:

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