Skip to main content
Glama
by ricleedo

reverse-geocode

Convert geographic coordinates into readable addresses to identify locations from latitude and longitude data.

Instructions

Convert coordinates to an address

Input Schema

NameRequiredDescriptionDefault
latitudeYesThe latitude
longitudeYesThe longitude

Input Schema (JSON Schema)

{ "properties": { "latitude": { "description": "The latitude", "type": "number" }, "longitude": { "description": "The longitude", "type": "number" } }, "required": [ "latitude", "longitude" ], "type": "object" }

Implementation Reference

  • The handler function that implements the reverse-geocode tool logic using Google Maps API.
    export async function reverseGeocode( params: z.infer<typeof reverseGeocodeSchema>, extra?: any ) { const apiKey = process.env.GOOGLE_MAPS_API_KEY; if (!apiKey) { throw new Error("GOOGLE_MAPS_API_KEY is required"); } try { const response = await googleMapsClient.reverseGeocode({ params: { latlng: [params.latitude, params.longitude], key: apiKey, }, }); const results = response.data.results; if (results.length === 0) { return { content: [ { type: "text" as const, text: "No results found for the given coordinates.", }, ], }; } const location = results[0]; return { content: [ { type: "text" as const, text: formatLocationToMarkdown( "Reverse Geocoded Location", location.formatted_address, params.latitude, params.longitude, location.place_id ), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error reverse geocoding coordinates: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
  • Zod schema defining input parameters for reverse-geocode tool (latitude and longitude).
    export const reverseGeocodeSchema = z.object({ latitude: z.number().describe("The latitude"), longitude: z.number().describe("The longitude"), });
  • src/index.ts:70-77 (registration)
    Registration of the reverse-geocode tool on the MCP server using the handler and schema.
    server.tool( "reverse-geocode", "Convert coordinates to an address", reverseGeocodeSchema.shape, async (params) => { return await reverseGeocode(params); } );
  • Helper function to format geocoding results as markdown, used by reverseGeocode.
    function formatLocationToMarkdown(title: string, address: string, lat: number, lng: number, placeId?: string): string { let markdown = `# ${title}\n\n`; markdown += `Address: ${address} \n`; markdown += `Coordinates: ${lat}, ${lng} \n`; if (placeId) markdown += `Place ID: \`${placeId}\` \n`; markdown += `Google Maps: [View on Maps](https://maps.google.com/?q=${lat},${lng})`; return markdown; }

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/ricleedo/Google-Service-MCP'

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