Map clicks and custom markers
With a map showing the user’s current location by zooming in at the right location and placing a marker there, we have a rudimentary knowledge of how to render the desired map and how to obtain the required permissions and the user’s current location.
In this section, we will learn how to respond to a user interacting with the map and how to use markers more extensively. We will learn how to move markers on the map and replace the default pin marker with custom icons. When we know how to let the user place a marker anywhere on the map, we can let them choose where to deploy the secret cat agent.
We need to add a listener to the GoogleMap
instance to listen for clicks on the map. Looking at our MapsActivity.kt
file, the best place to do so would be in onMapReady(GoogleMap)
. A naïve implementation might look like this:
override fun onMapReady(googleMap: GoogleMap) { mMap = googleMap.apply { ...