Skip to main content
Glama

maps_geo

Convert structured addresses and landmark names into precise latitude-longitude coordinates for location-based applications.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes
cityNo

Implementation Reference

  • 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)}"}

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