Creating a custom application
We are now going to create a custom map application. When we tap anywhere on a map, a dialog is shown, which takes text for Title and Snippet for a marker as input. The marker is placed on the clicked location along with an information window.
We can add as many markers as we need and remove a marker by tapping on the information window. Let's proceed!
Our activity layout code is the same as the one we've used before:
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.MapFragment" />
activity_maps.xml
Next, we need to create a custom dialog to add the marker. It has two EditText
widgets and two button widgets. The EditText
widgets are used to get the title and snippet text as input. One button is used to add the marker, the other is to cancel it...