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

Working with map events


The Google Map's API allows us to listen for events on a map similar to those that we listen to on buttons and other views. The events that are available for this purpose are:

  • Map click / long click events

  • Camera change events

  • Indoor map events

Let's discuss these events in detail.

Map click/long click events

To handle map click events, we should use the OnMapClickListener interface on the GoogleMap object. To enable this, call the setOnMapClickListener() method on the GoogleMap object, which takes the GoogleMap.OnMapClickListener() interface as a parameter. When you click anywhere on a map, the onMapClick() method is called. In this example, we shall display a toast that shows the latitude and longitude of the location that has been clicked on. Now, we are going to display the output similar to the following screenshot:

The complete code for the onMapReady() callback method is as follows:

@Override
    public void onMapReady(GoogleMap map) {

        map.setOnMapClickListener...