Google Maps Android API v2

Google Maps Android API Utility Library

Looking for advanced features to add to your maps? The Google Maps Android API Utility Library is an open-source library of classes that are useful for a range of applications.

  1. Introduction
  2. Add heatmaps to your map
  3. Customise markers via bubble icons
  4. Manage marker clusters
  5. Encode and decode polylines
  6. Calculate distances, areas and headings via spherical geometry

Introduction

The source of the Google Maps Android API Utility Library is available on GitHub. The GitHub repository includes the utility classes and a demonstration application that illustrates the use of each class. To get started, follow the setup guide for Eclipse. Alternatively, the project's website includes a getting-started guide for Android Studio/Gradle and Maven. The reference documentation is also available on GitHub. Below is an overview of the utilities in the library.

In this video, Chris Broadfoot discusses the utility library, with a focus on polyline decoding, spherical geometry, and bubble icons:

The utilities

A map with a heatmap

Add heatmaps to your map

Heatmaps make it easy for viewers to understand the distribution and relative intensity of data points on a map. Rather than placing a marker at each location, heatmaps use color and shape to represent the distribution of the data. Create a HeatmapTileProvider, passing it a collection of LatLng objects representing points of interest on the map. Then create a new TileOverlay, passing it the heatmap tile provider, and add the tile overlay to the map.

For details, see the documentation on the Google Maps Android Heatmap Utility.

A map with bubble icons

Customise markers via bubble icons

Add a IconGenerator to display snippets of information on your markers. This utility provides a way of making your marker icons look a bit like info windows, in that the marker itself can contain text and other content. The advantage is that you can keep more than one marker open at the same time, whereas only one info window can be open at once. You can also style the markers, change the orientation of the marker and/or content, and change the marker's background image/nine-patch.

A map with clustered markers

Manage marker clusters

The ClusterManager helps you manage multiple markers at different zoom levels. This means you can put a large number of markers on a map without making the map hard to read. When a user views the map at a high zoom level, the individual markers show on the map. When the user zooms out to a lower zoom level, the markers gather together into clusters, to make viewing the map easier.

For details, see the documentation on the Google Maps Android Marker Clustering Utility.

A map with an encoded polyline

Encode and decode polylines

The PolyUtil is useful for converting encoded polylines and polygons to latitude/longitude coordinates, and vice versa.

In Google Maps, the latitude and longitude coordinates that define a polyline or polygon are stored as an encoded string. See the detailed explanation of polyline encoding. You may receive this encoded string in a response from a Google API, such as the Google Directions API.

You can use PolyUtil in the Google Maps Android API Utility Library to encode a sequence of latitude/longitude coordinates ('LatLngs') into an encoded path string, and to decode an encoded path string into a sequence of LatLngs. This will ensure interoperability with the Google Maps API web services.

Calculated distance between two points on a map

Calculate distances, areas and headings via spherical geometry

Using the spherical geometry utilities in SphericalUtil, you can compute distances, areas, and headings based on latitudes and longitudes. Here are some of the methods available in the utility:

  • computeDistanceBetween() – Returns the distance, in meters, between two latitude/longitude coordinates.
  • computeHeading() – Returns the bearing, in degrees, between two latitude/longitude coordinates.
  • computeArea() – Returns the area, in square meters, of a closed path on the Earth.
  • interpolate() – Returns the latitude/longitude coordinates of a point that lies a given fraction of the distance between two given points. You can use this to animate a marker between two points, for example.

Refer to the reference documentation for a full list of methods in the utility.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.