Geoapify + Leaflet: Address Search Plugin Demo

Set bias to the map view to search addresses nearby

More examples: Add the address autocomplete plugin, Custom style, Localize results, Beautiful markers

To force Geoapify Address Autocomplete to use the visible map area as a preferable search area, set the "mapViewBias" flag to true:


const addressSearchControl = L.control.addressSearch(myAPIKey /* get an API Key on https://myprojects.geoapify.com */, {
  position: 'topleft',
  mapViewBias: true,
  resultCallback: (address) => {
    ...
  },
  suggestionsCallback: (suggestions) => {
    console.log(suggestions);
  }
});
map.addControl(addressSearchControl);
L.control.zoom({ position: 'bottomright' }).addTo(map);
      

You can also get the rough user location with the IP Geolocation API:


fetch(`https://api.geoapify.com/v1/ipinfo?apiKey=${myAPIKey}`).then(result => result.json()).then(result => {
  map.setView([result.location.latitude, result.location.longitude], 8);
});