How to set parameters for mapbox geocoder so that it only returns zip codes?

456 views Asked by At

I'm currently working with a map and I only want my users to be able to search by their own zip code. Is it possible to customize the functionality of it in this way? here is the only code I'm working with for it:

'map.addControl(
    new MapboxGeocoder({
    accessToken: mapboxgl.accessToken,
    mapboxgl: mapboxgl
    })
);'
1

There are 1 answers

0
Steve Bennett On

You can limit the returned types by using the types property to values defined here: https://docs.mapbox.com/api/search/#data-types

map.addControl(
    new MapboxGeocoder({
        accessToken: mapboxgl.accessToken,
        mapboxgl: mapboxgl,
        types: 'postcode'
    })
);