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

Display maps


In this section, we are going to learn how to display a desired location in Google Maps. Here, we need to use the keyword geo along with the coordinates that should be displayed in the map. Let's test this with an example.

Our main layout consists of only a single button, which helps us launch Google Maps. The code is as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">
    <Button
        android:id="@+id/btn"
        android:text="Display in Google map"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

activity_maps.xml

Our activity contains the code to handle the click button. It checks whether Google Maps exists. If it exists, it will launch the application. The code is as follows:

package com.raj.map;

import android.app.Activity...