Working with map events
The Google Map's API allows us to listen for events on a map similar to those that we listen to on buttons and other views. The events that are available for this purpose are:
Map click / long click events
Camera change events
Indoor map events
Let's discuss these events in detail.
Map click/long click events
To handle map click events, we should use the OnMapClickListener
interface on the GoogleMap
object. To enable this, call the setOnMapClickListener()
method on the GoogleMap
object, which takes the GoogleMap.OnMapClickListener()
interface as a parameter. When you click anywhere on a map, the onMapClick()
method is called. In this example, we shall display a toast that shows the latitude and longitude of the location that has been clicked on. Now, we are going to display the output similar to the following screenshot:
The complete code for the onMapReady()
callback method is as follows:
@Override public void onMapReady(GoogleMap map) { map.setOnMapClickListener...