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

Adding information with markers


Markers can be used to indicate a particular location on a map. A marker can be customized by changing its color or using a custom image instead of a marker icon. This image is an example of a marker:

How to add a marker?

We need to use a Marker object to work with markers. A new marker can be added with the following method:

GoogleMap.addMarker()

This code takes the parameter as the MarkerOptions object. The latitude and longitude are set for the map using a LatLng object. The latitude and longitude can also be set as follows

MarkerOptions().position()

This method takes the LatLng object as a parameter. Now, let's create a sample app that displays a marker in Newark city. Let's see how we can code it. The code for our main layout is the same as the one we used in our previous chapters.

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