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. The GitHub repository includes the utility
classes and a demo app that illustrates the use of each
In this video, Chris Broadfoot discusses the utility library, with a focus on
polyline decoding, spherical geometry, and bubble icons.
Add the following dependency to your app's Gradle build file:
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.
Using this utility, you can convert
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
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
passing it the heatmap tile provider, and add the tile overlay to the
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.
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.
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
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.
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.