Start a Project

Working with AMap in Android – Part 3 (Adding Marker Click Listener and InfoWindow)

In the last part of the working with AMaps, we learned about changing the map type and adding markers. Now we will learn about adding click listeners on the markers and showing InfoDialog on them.

 

After you have created the AMap and added the marker on it, You will have to implement an Interface called OnMarkerClickListener in your activity and override its onMarkerClick(Marker marker) function which will be called whenever a marker is clicked.

 

You can perform any kind of task like showing toasts or animating the marker. Let us see an example of this. After the implementation of the Interface, you need to set the click listener on your_amap.

And now whenever your marker is clicked onMarkerClick(Marker marker) function will be called and you can perform the task in it. Look at the example given below

In the above code snippet, You can see that we have performed two actions on marker click. One is making a toast and the other one is making an animation of marker jumping. You can check the jumpPoint fucntion below.

 

Now if you want to add an InfoWindow on the marker like showing some important information over the marker. It is quite simple. All you need to do is while creating your marker use title function for adding the title and snippet function for adding some details. Look at the below provided code snippet for example.

That’s all for this section, We will study about more amazing AMap functionalities in the next sections

Thank you very much, this is Vedesh Kumar signing off.

Exit mobile version