When working with markers in Google Maps, handling click events is essential for creating interactive
maps.
In this video, we're going to learn how to implement and manage marker click events.
Let's start with the simple click event on every marker.
You can click it.
So for example, if I click on it, the camera will zoom and make it at center and display this info
window.
This info window contains a title and a snippet, and we talked about it in the previous video.
Okay, now let's handle the custom click events.
If we go to the marker, we notice that we have onClick parameter.
This onclick takes a marker as a parameter and returns a boolean when in the in the expression.
Okay, so let me start on click.
We need to pass a lambda expression.
And here let me set a marker as a parameter.
You can for example show info window and log.
For example the that look at the key is tag and the message is you clicked Singapore marker.
Then we need to return a boolean which is true to consume the event.
Okay let me check.
Run again.
Open the look at search for tag and here click on the marker.
You notice you clicked Singapore marker.
Okay again if you click, the messages will appear.
Okay this is how we handle the click event on the marker.
The onClick event Lambda expression receives the marker object that was clicked.
Return it true to consume the event, prevent default info window behavior, and return false if you
want to show the default window or info window.
So here false if you notice if I click on the marker, we are.
We are not displaying the info window.
So again if I click you can notice that the click event is um is triggered and using.
True we are not displaying the info window.
If I use false like this.
Run the application again.
Click the marker.
We are displaying the message and displaying the info window.
So this is the difference between using the true and false boolean and returning it.
Okay, so true to consume the event and prevent default info window behavior.
False.
If you want to show the default info window.