Skip to main content
Glama
by sinch
geocoding.ts1.08 kB
import axios from 'axios'; interface GeocodingAddress { latitude: number; longitude: number; formattedAddress: string; } export const getLatitudeLongitudeFromAddress = async (address: string): Promise<GeocodingAddress> => { const fallbackCoordinates: GeocodingAddress = { latitude: 0, longitude: 0, formattedAddress: 'Unknown' }; try { const url = 'https://maps.googleapis.com/maps/api/geocode/json'; const queryParams = { address, key: process.env.GEOCODING_API_KEY }; const response = await axios.get(url, { params: queryParams }); const data = response.data; if (data.status === 'OK') { const location = data.results[0].geometry.location; return { latitude: location.lat, longitude: location.lng, formattedAddress: data.results[0].formatted_address }; } else { console.error('Geocoding failed:', data.status); return fallbackCoordinates; } } catch (error) { console.error('Request failed:', error); return fallbackCoordinates; } };

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/sinch/sinch-mcp-server'

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