Access Arguments in UI Events

Learn how to pass and access event arguments to UI events within the Maps JavaScript API.

We'll cover the following

Work with UI events

Within the Maps JavaScript API, UI events can pass event arguments that can be accessed through an event listener. These event arguments can be accessed with an event listener in the same way the properties of JavaScript objects are accessed.

For example, the click event is a UI event that passes the MouseEvent argument to the event listener. One property that the MouseEvent argument includes is latLng, which denotes the precise location where the map is clicked. The MouseEvent argument’s latLng property can be accessed with an event listener in the following way:

map.addListener("click", (MouseEvent) => {
	console.log(MouseEvent.latLng);
});

Note: The behavior mentioned above is unique to UI events since events related to state change don’t pass arguments.

Get hands-on with 1200+ tech skills courses.