Book Image

Learning Android Google Maps

Book Image

Learning Android Google Maps

Overview of this book

This book helps you to overcome the most common problems faced by users and helps you create a successful map application without any hassle. The book starts with a brief description of how to set up an environment and obtain an API key to create your map application. This book will teach you about adding markers, overlays, and information windows to the map in detail. You will then dive deep into customizing various types of maps and working with location data and Google Street view. By the end of this book, you will be able to create succinct map applications in Android using Google maps efficiently.
Table of Contents (18 chapters)
Learning Android Google Maps
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

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...