spockshr
spockshr

Reputation: 382

Mapbox Geocoder integration with on-screen keyboard

I tried out this mapbox geocoding example: https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder/ in my application.

Now, I am trying to do the same thing, but instead of using a physical keyboard, I am trying to use on-screen keyboard like: https://virtual-keyboard.js.org/

But at the moment, the inputs from the virtual-keyboard is not triggering the mapbox geocoder. How can I link the two components?

Upvotes: 0

Views: 358

Answers (1)

Adriana Babakanian
Adriana Babakanian

Reputation: 1299

As indicated in the implementation of the keyevent function here in the mapbox/mapbox-gl-geocoder source code, the geocoder responds to keydown events, which are fired when a key is pressed.

The documentation for the virtual keyboard you linked includes an onKeyPress method to which you can pass a callback function to be executed when a key is pressed on the virtual keyboard. You can implement a function to simulate a keydown event (as described in this Stack Overflow post) equivalent to the last character from getInput. This should have the effect of triggering the geocoder as through an actual key was pressed.

Upvotes: 1

Related Questions