Skip to main content
Glama
cablate

MCP Google Map Server

maps_reverse_geocode

Convert latitude and longitude coordinates into precise addresses using Google Maps API integration, enabling accurate location identification.

Instructions

將座標轉換為地址

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYes緯度
longitudeYes經度

Implementation Reference

  • Main handler function for the maps_reverse_geocode tool. It instantiates PlacesSearcher with the current API key and calls its reverseGeocode method with the provided latitude and longitude.
    async function ACTION(params: any): Promise<{ content: any[]; isError?: boolean }> {
      try {
        // Create a new PlacesSearcher instance with the current request's API key
        const apiKey = getCurrentApiKey();
        const placesSearcher = new PlacesSearcher(apiKey);
        const result = await placesSearcher.reverseGeocode(params.latitude, params.longitude);
    
        if (!result.success) {
          return {
            content: [{ type: "text", text: result.error || "Failed to reverse geocode coordinates" }],
            isError: true,
          };
        }
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result.data, null, 2),
            },
          ],
          isError: false,
        };
      } catch (error: any) {
        const errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
        return {
          isError: true,
          content: [{ type: "text", text: `Error reverse geocoding: ${errorMessage}` }],
        };
      }
    }
  • Zod schema definition for input parameters (latitude and longitude) and the inferred TypeScript type.
    const SCHEMA = {
      latitude: z.number().describe("Latitude coordinate"),
      longitude: z.number().describe("Longitude coordinate"),
    };
    
    export type ReverseGeocodeParams = z.infer<z.ZodObject<typeof SCHEMA>>;
  • src/config.ts:42-46 (registration)
    Registration of the maps_reverse_geocode tool in the server configuration, referencing the exported constants and ACTION from reverseGeocode.ts.
      name: ReverseGeocode.NAME,
      description: ReverseGeocode.DESCRIPTION,
      schema: ReverseGeocode.SCHEMA,
      action: (params: ReverseGeocodeParams) => ReverseGeocode.ACTION(params),
    },
  • Supporting method in PlacesSearcher class that calls the underlying GoogleMapsTools reverseGeocode and handles response/error formatting.
    async reverseGeocode(latitude: number, longitude: number): Promise<ReverseGeocodeResponse> {
      try {
        const result = await this.mapsTools.reverseGeocode(latitude, longitude);
    
        return {
          success: true,
          data: result,
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : "An error occurred during reverse geocoding",
        };
      }
    }
Install Server

Other Tools

Related Tools

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/cablate/mcp-google-map'

If you have feedback or need assistance with the MCP directory API, please join our Discord server