mapbox / mapbox-gl-directions

Directions plugin for mapbox-gl-js using Mapbox Directions API.
https://mapbox.com/mapbox-gl-js/example/mapbox-gl-directions/
ISC License
235 stars 124 forks source link

Show autocomplete addresses that are close to the users geolocation or map view #270

Open subhyde opened 3 years ago

subhyde commented 3 years ago

When entering an address. The autocomplete recommendation should be targeted around the map's current position.

If I am in new york and I'm searching for a street in new york. the same street name in brazil should not be the first recommendation for an autocompleted field.

Is there a work around for this?

todd-lm commented 3 years ago

You can set the proximity that the Geocoder uses for search to a specific point like this:

var directions = new MapboxDirections({

  accessToken: mapboxgl.accessToken,
  profile: 'mapbox/cycling',
  alternatives: true,
  controls: {
    profileSwitcher: false
  },
  geocoder: {
    proximity: [-73.987865,40.748297]  //Change this line to a longitude/latitude coordinate that the Geocoder will try to find results near.
  }