passing api key to React Leaflet geosearch

Viewed 34

I'm trying to pass an api key to react leaflet geosearch using the Esri provider. (docs here) It currently works without passing a key, but I'd like to add my own.

My code is as follows:

const SearchControl = (props) => {
  const map = useMap()

  useEffect(() => {
    const searchControl = new GeoSearchControl({
      provider: props.provider,
      ...props,
    })

    map.addControl(searchControl)
    return () => map.removeControl(searchControl)
  }, [props])

  return null
}


const apikey='someapikey'


const prov = new EsriProvider()

The arcgis docs that Leaflet geosearch point to are designed a little differently.(docs)

I'm guessing it's a param like so:

const provider = new EsriProvider({
  params: {
    api_key: 'apikey',
  },
});

but my dashboard hasn't updated me to any usage.

Thanks in advance

EDIT: I've found an answer. It turns out this specific provider input is a little dated. I went with the 'BingProvider' and was able to use my bing api like so

const prov = new BingProvider({
  params: {
    key: apiKey,
  },
})
0 Answers
Related