Maps SDK for Android Utility Library

Select platform: Android iOS

Looking for advanced features to add to your maps? The Maps SDK for Android Utility Library is an open-source library of classes that are useful for a range of applications. The GitHub repository includes the utility classes and a demo app that illustrates the use of each class.

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

Quick setup

To install the Maps SDK for Android Utility Library, follow the setup guide.

The utilities

A map with a GeoJSON layer

Import GeoJSON onto your map

You can store features in GeoJSON format and use this utility to render them as a layer on top of a map. Call addLayer() to add your GeoJSON data to the map. You can also add individual features by calling addFeature(), passing in a GeoJsonFeature object.

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

A map with a KML layer

Import KML onto your map

Using this utility, you can convert KML objects into geographical shapes and render them as a layer on top of a map. Call addLayerToMap() to add your layer to the map. You can access properties in a KML object by calling getProperties() on any Placemark, GroundOverlay, Document or Folder.

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

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

Customize 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 multiple layers

Add multiple layers to the same map

You can show features from GeoJSON, KML, and clusters — as well as your own markers, polylines, and polygons — all on the same map. These layers can also be made interactive by adding a click listener to each layer. Simply instantiate the MarkerManager, GroundOverlayManager, PolygonManager, and PolylineManager classes and pass them into the constructors of GeoJsonLayer, KmlLayer, ClusterManager when you set them up. You can then use the above Manager classes directly to add your own markers, polylines, and polygons to the map.

For details, see the documentation on the Google Maps Android Multi Layer Demo.

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 Directions API.

You can use PolyUtil in the Maps SDK for Android 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 APIs 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.