Skip to content

50,000 free calls a month, card-free. Get an API key →

Documentation menu
docs / examples / geocode
Example

Geocode with a location bias

Free text to coordinates, with a bias point that reorders candidates and a bounding box that excludes anything outside it outright. Reverse lookups add a distance and, on POI hits, a details object straight from OpenStreetMap.

ts
import { Geocoder } from "@mapmap/maps";

// Pass the map to reuse its baseUrl and apiKey, or construct it standalone
// with { baseUrl, apiKey } and no MapLibre dependency at all.
const geocoder = new Geocoder(map);

const hits = await geocoder.geocode("tate modern", {
  bias: map.map.getCenter(),
  limit: 5,
});
// hits[0]: { lngLat: [lng, lat], name, kind, street, city, postcode,
//            categories?, details?, id?, raw }

// Reverse: point to nearest hits, filtered to POIs.
const places = await geocoder.reverse([-0.09934, 51.50743], { kinds: ["poi"] });