Requirement 3: Tap the Map to Drop a Marker with Annotations
Users tap anywhere on the map to add a marker.
A dialog box prompts the user to enter a custom annotation.
The marker shows:
Coordinates of the tap.
User-entered annotation.
Markers are cumulative, and all remain visible.
Lecture Slides for Requirement 3: Tap the Map to Drop a Marker with User Annotations
Let’s dive into how we can dynamically place markers on a map by tapping it. Together, we’re unlocking the full power of user interaction with Google Maps. Markers aren’t just coordinates anymore—they’ll include custom notes that we can add in real time. All previous markers remain, and the app becomes a visual diary of user interactions.
Slide 1: What Are We Building?
Title: Requirement 3: Tap to Drop Markers with Annotations
What We’re Delivering:
Users can tap anywhere on the map to drop a marker.
Each marker will include:
Coordinates (latitude, longitude)
A user-entered note (annotation)
All markers are cumulative—previous markers remain on the map.
Why This Is Cool:
We’re building a fully interactive map that evolves with the user. This feature ties everything we’ve learned so far into a seamless experience.
Slide 2: How Tapping the Map Works
Title: What Happens When We Tap the Map?
User Interaction:
A tap on the map sends the coordinates (latitude and longitude).
The app listens for this tap and triggers a response.
App Response:
The coordinates are passed into a dialog box where the user can enter a note.
The app saves the marker, adds it to the map, and ensures it persists.
Result:
The map accumulates markers, each containing unique information provided by the user.
Slide 3: The Workflow in Action
Title: Understanding the Flow
Tap the Map:
The app detects where we tap.
Dialog Box Appears:
A text input field allows us to provide a note for the marker.
Place the Marker:
The app places a marker with:
The coordinates (latitude and longitude).
The user-entered annotation.
Markers Accumulate:
Every marker stays visible as new ones are added.
This feature makes our map dynamic and personalized, allowing us to make the map our own.
Slide 4: Adding a Listener for Taps
Title: The Code for Detecting Taps
In onMapReady, we set up a listener to detect taps:
googleMap.setOnMapClickListener { latLng ->
showAnnotationDialog(latLng)
}
Key Points:
setOnMapClickListener: Google Maps SDK method for listening to taps.
latLng: The exact location of the tap (latitude, longitude).
Next Step: Pass the tapped location to a dialog box for user input.
Slide 5: Prompting for Annotations
Title: Asking the User for Notes
When the map is tapped, we open a dialog for user input. Here’s how we implement it:
private fun showAnnotationDialog(latLng: LatLng) {