Need to capture event for geocode when the result is not selected
Hi ,
I need the details of of how to capture event when we type something in geocoder and doesn't select any results from the autocomplete ?
I referred the below link and added the marker after selecting the result using geocoder.on('result', function(ev) {} ). This will get the control only if we select results from autocomplete. How to capture the event where user types something in the geocoder and doesn't select any results form autocomplete. I need this to clear previously selected address from my component state.
https://docs.mapbox.com/mapbox-gl-js/example/point-from-geocoder-result/
Thanks Girish T S
Something like geocoder._inputEl.addEventListener('blur', function (e) { console.log('blur', e) });?
map.addControl( new MapboxGeocoder({ accessToken: mapboxgl.accessToken, mapboxgl: mapboxgl, getItemValue: e => { console.log(e); } }) );
e contains everything you could want to know about the selected location
Here is a working example
map.addControl( new MapboxGeocoder({ accessToken: mapboxgl.accessToken, mapboxgl: mapboxgl, getItemValue: ({ center, place_name }) => { Api.logUserGeoSearch(center[1], center[0], place_name); return place_name; } }) );