Map Clicks and Custom Markers
With a map showing the user's current location by zooming in at the right location and placing a pin there, we have rudimentary knowledge of how to render the desired map, as well as knowledge of 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 how to replace the default pin 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.
To listen for clicks on the map, we need to add a listener to the GoogleMap
instance. Looking at our MapsActivity.kt
file, the best place to do so would be in onMapReady(GoogleMap)
. A naïve implementation would look like this:
override fun onMapReady(googleMap: GoogleMap) { mMap = googleMap.apply...