Skip to main content
Glama

get_reverse_geocode

Convert geographic coordinates into a human-readable address using Google Maps data. Input latitude and longitude values to retrieve location information.

Instructions

Convert coordinates to an address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYesLatitude coordinate
longitudeYesLongitude coordinate

Implementation Reference

  • Core implementation of reverse geocoding logic using Google Maps Places API client. Validates coordinates, calls reverseGeocode API, processes the first result, and handles errors.
    async reverseGeocode( latitude: number, longitude: number ): Promise<ServiceResponse<Location>> { try { validateCoordinates(latitude, longitude); const response = await this.client.reverseGeocode({ params: { key: config.googleMapsApiKey, latlng: { lat: latitude, lng: longitude }, language: config.defaultLanguage as Language, }, }); if (response.data.results.length === 0) { throw new Error("No results found for the given coordinates"); } const result = response.data.results[0]; return { success: true, data: { lat: latitude, lng: longitude, address: result.formatted_address, placeId: result.place_id, }, }; } catch (error) { return handleError(error); } }
  • Registers the 'get_reverse_geocode' tool with MCP server, including schema reference and a thin async handler that delegates to PlacesSearcher.reverseGeocode and formats the response.
    server.registerTool( "get_reverse_geocode", { title: "Reverse Geocode", description: "Convert coordinates to an address", inputSchema: ReverseGeocodeSchema, }, async (args) => { try { const result = await placesSearcher.reverseGeocode( args.latitude, args.longitude ); return { content: [ { type: "text", text: JSON.stringify(result, null, 2) }, ], isError: !result.success, }; } catch (error) { const errorResponse = handleError(error); return { content: [ { type: "text", text: errorResponse.error || "An unknown error occurred", }, ], isError: true, }; } } );
  • Zod schema defining the input parameters for the get_reverse_geocode tool: latitude and longitude numbers.
    export const ReverseGeocodeSchema = { latitude: z.number().describe("Latitude coordinate"), longitude: z.number().describe("Longitude coordinate") };

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/BACH-AI-Tools/MCP-Google-Maps'

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