Is there a way to detect keypress only when the Google Maps canvas is in focus?
Google Maps JavaScript API V3 has built-in keyboard shortcuts. When a user clicks on a map tile or drags it, the map becomes in focus, and will respond to keyboard shortcuts. If you click anywhere else outside the map canvas, those keyboard shortcuts will no longer work.
I would like to extend some of these shortcuts (specifically the arrow keys) to perform additional actions.
To confirm the key is associated with the project: Go to the Credentials section, which can be accessed from the left side bar under Google Maps Platform > Credentials.
The following code defines the HTML elements to hold the Google Map, search input field, and geo-location data. Create an input element ( searchInput ) where the autocomplete addresses search will be added. Create a DIV element ( map ) to display the Google Map. Specify the elements to display the geolocation data.
You can disable the keyboard shortcuts in Google Maps like here
https://developers.google.com/maps/documentation/javascript/reference?hl=en#MapOptions
and then you can use the keyboard shortcuts for your own purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With