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

Using a Projection class


Google maps provides a Projection class, which has some useful methods. The fromScreenLocation() method converts screen pixels in point coordinates to LatLng coordinates.

The toScreenLocation() method converts the LatLng coordinates to the screen pixel point coordinates.

The getVisibleRegion() method returns the VisibleRegion object from which we can obtain LatLngBounds.

Let's see an example where we are going to convert a screen pixel Point coordinate, (100,100), to a LatLng coordinate when the camera changes. From this, we get the visible region and display the north-east and south-west corners of the LatLng coordinate.

Then, when the map is clicked on, we obtain the LatLng coordinate of the clicked location and convert it to the screen pixels point coordinate.

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

@Override
    public void onMapReady(final GoogleMap map) {

        map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() ...