Geocoding search results closer to specific point

To enhance search results, the geocoding control prioritizes locations that are closer to a specific geographical point. By utilizing the proximity options in the control constructor, results near the provided point are ranked higher.

In the given example, we aim to prioritize results that are near Times Square in New York (e.g., “Park Avenue”). We are using a define a geographical point by its latitude and longitude [lng, lat], for this you must use the fixed option.


proximity: [
  {
    type: "fixed",
    coordinates: [lng, lat],
  },
]

You can also use the map center coordinates instead of a specific coordinate. For example:


proximity: [
  {
    "type":"map-center",
    "minZoom":12
  }
]

For a complete list of geocoding control options, refer to the Geocoding control’s reference documentation.

NPM module setup


npm install --save @maptiler/sdk @maptiler/geocoding-control
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
import { GeocodingControl } from '@maptiler/geocoding-control/maptilersdk';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
  container: 'map', // container id
  style: MapStyle.STREETS.DARK,
  center: [-73.986644,40.756140], // starting position [lng, lat]
  zoom: 14, // starting zoom
});
//set geocoding control prioritize results near Time Square in New York
const gc = new GeocodingControl({
  proximity: [
    {
      type: "fixed",
      coordinates: [-73.986644, 40.75614],
    },
  ]
});
map.addControl(gc, 'top-left');

Learn more

Check the MapTiler Geocoding control API reference for all search options. For example specifying the language of the results, etc.

Do you want to see how the geocoder component is made? Check the MapTiler Geocoding control repository. You can also use it as inspiration to create your component.

Discover the process of integrating the geocoding control feature into your React (Geocoding React component repository) or Svelte (Geocoding Svelte component) applications. Additionally, you have the option to use the VanillaJS version to customize it for any of your applications.

Are you currently using a different map library? No worries! Learn how to incorporate the geocoding control functionality with Leaflet (Leaflet Geocoding control), OpenLayers (OpenLayers Geocoding control), or MapLibre GL JS (MapLibre GL JS Geocoding control).

Geocoding: Show place search results

Geocoding API

Tutorials

Search for places using the MapTiler Geocoding API.

Geocoding limit results by area (bounding box)

Geocoding limit results by area

Examples

Limit geocoding search results to a specific bounding box area.

Geocoding search for POIs near the user's location

Geocoding search for POIs near the user's location

Examples

Filter geocoding search results by specific place types.

Geocoding search results to specified country(ies)

Geocoding search results to specified country(ies)

Examples

Limit geocoding control search results to specific countries.

Was this helpful?