Getting the coordinates of a mouse click

The mouse has been the most effective input device for computers for a long time. Nowadays, there is an attempt to change it with touchscreens, but nothing can be compared to the ease of use that a mouse provides.

The mouse has different interactions on maps, such as click, double-click, right-click, move, and drag. These events can be handled in different ways to interact with users.

In this recipe, we will get the coordinates of a mouse click on any point on the map. Users will see an info window upon a mouse click, which can be seen in the following screenshot:

Getting the coordinates of a mouse click

This is how we achieve the creation of a map ...

Get Google Maps JavaScript API Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.