Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting keypress in Google Maps

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.

like image 674
Andrew Avatar asked Jul 19 '12 23:07

Andrew


People also ask

How do I know if my map key is working?

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.

How do I Create an autocomplete search box in Google Maps?

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.


1 Answers

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.

like image 124
user1356326 Avatar answered Oct 14 '22 02:10

user1356326