Geocode an address with Thinwrap (TypeScript)
Convert an address to coordinates via the Thinwrap unified Geocoding facade in TypeScript — same call shape for Google, Mapbox, HERE, ESRI, and TomTom.
1. Install
npm install @thinwrap/location2. Send the call
import { Geocoding } from '@thinwrap/location';
const geocoding = new Geocoding('google', {
apiKey: process.env.GOOGLE_MAPS_API_KEY!,
});
const result = await geocoding.geocode({
address: '1600 Amphitheatre Parkway, Mountain View, CA',
countryFilter: ['US'], // hard ISO 3166-1 alpha-2 filter
});
// Pick the top candidate; result.candidates[] is non-empty on success.
const top = result.candidates[0];
console.log(top.location.lat, top.location.lng);
// Reverse-geocode + autocomplete are on the same facade:
const reverse = await geocoding.reverseGeocode({
location: { lat: 37.4221, lng: -122.0841 },
});
console.log(reverse.candidates[0]?.formattedAddress);
Same code works for all supported providers — just change the provider ID.