Skip to main content
Glama

coordinates_to_location

Use reverse geocoding to convert latitude and longitude coordinates into specific location names, enabling precise identification of geographic points for GIS applications.

Instructions

Convert latitude/longitude coordinates to location name using reverse geocoding

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYesLatitude coordinate
longitudeYesLongitude coordinate

Implementation Reference

  • The main handler function `coordinatesToLocation` that performs reverse geocoding. It validates inputs, makes an HTTPS GET request to Nominatim OSM service with the coordinates, parses the JSON response, and returns structured location information including display_name, address, type, etc.
    async coordinatesToLocation(args: any): Promise<ToolResponse> { const { latitude, longitude } = args; if (latitude === undefined || longitude === undefined) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameters: latitude, longitude' ); } try { console.error(`[Converting] Coordinates (${latitude}, ${longitude}) to location name`); // Using Nominatim OSM service (free, but has usage limitations) const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}`; return new Promise<ToolResponse>((resolve, reject) => { // Use the imported https module directly const req = https.request(url, { method: 'GET', headers: { 'User-Agent': 'GisFormatMcpServer/1.0' } }, (res) => { if (res.statusCode !== 200) { reject(new Error(`Geocoding service returned ${res.statusCode}: ${res.statusMessage}`)); return; } let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { try { const parsedData = JSON.parse(data); // Always return detailed format const result = { displayName: parsedData.display_name, address: parsedData.address, type: parsedData.type, osmId: parsedData.osm_id, osmType: parsedData.osm_type, category: parsedData.category }; resolve(this.formatToolResponse(JSON.stringify(result, null, 2))); } catch (error) { reject(new Error(`Failed to parse geocoding response: ${error instanceof Error ? error.message : String(error)}`)); } }); }); req.on('error', (error) => { reject(new Error(`Geocoding request failed: ${error.message}`)); }); req.end(); }); } catch (error) { console.error('[Error] Coordinates to location conversion failed:', error); throw new McpError( ErrorCode.InternalError, `Coordinates to location conversion failed: ${error instanceof Error ? error.message : String(error)}` ); } }
  • The input schema definition for the `coordinates_to_location` tool, specifying required `latitude` (number) and `longitude` (number) properties.
    inputSchema: { type: 'object', properties: { latitude: { type: 'number', description: 'Latitude coordinate', }, longitude: { type: 'number', description: 'Longitude coordinate', } }, required: ['latitude', 'longitude'], },
  • src/index.ts:255-272 (registration)
    Registration of the `coordinates_to_location` tool in the ListTools response, including name, description, and input schema.
    { name: 'coordinates_to_location', description: 'Convert latitude/longitude coordinates to location name using reverse geocoding', inputSchema: { type: 'object', properties: { latitude: { type: 'number', description: 'Latitude coordinate', }, longitude: { type: 'number', description: 'Longitude coordinate', } }, required: ['latitude', 'longitude'], }, }
  • src/index.ts:296-297 (registration)
    Registration of the tool handler dispatch in the CallToolRequest switch statement: case 'coordinates_to_location' calls this.coordinatesToLocation.
    case 'coordinates_to_location': return await this.coordinatesToLocation(request.params.arguments);

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/ronantakizawa/gis-dataconvertersion-mcp'

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