Version 3.1.0 beta of the Maps SDK for Android is a new implementation with the same API surface as the previous version (all classes and methods remain the same), and some new features for you to try:
- Maps customization
- Marker collision handling
- Polyline customization
This guide shows you how to use the new features.
Maps customization (beta)
Maps customization provides a variety of tools and features that let you more easily customize and manage how your maps are styled. Rather than styling your map in code using the Maps APIs and SDKs, you can manage and style your maps in the Google Cloud Console. For more information, see Android Map Customization Overview.
Marker collision handling (beta)
You can specify whether custom markers should override default basemap labels when there is a collision, and to indicate relative priority between custom markers. For more information, see Marker Collision Handling (Android).
Polyline Customization (beta)
There are now several new ways to customize the appearance of polylines:
- Multicolored polylines set polyline segments to different colors.
- Gradient polylines color a polyline using a gradient of two colors.
- Stamped polylines style a polyline using repeating bitmaps.
Creating a multicolored polyline
You can use spans to individually color segments of a polyline, by creating
StyleSpan
objects, and adding them to PolylineOptions
using the addSpan()
or addSpans()
methods. By default, each item in the array will set the color
of the corresponding line segment. The following example shows setting segment
colors to create a polyline with red and green segments:
Java
Polyline line = map.addPolyline(new PolylineOptions() .add(new LatLng(47.6677146,-122.3470447), new LatLng(47.6442757,-122.2814693)) .addSpan(new StyleSpan(Color.RED)) .addSpan(new StyleSpan(Color.GREEN)));
Kotlin
val line = map.addPolyline( PolylineOptions() .add(LatLng(47.6677146, -122.3470447), LatLng(47.6442757, -122.2814693)) .addSpan(StyleSpan(Color.RED)) .addSpan(StyleSpan(Color.GREEN)) )
Creating a gradient polyline
You can define a gradient by specifying two 32-bit alpha-red-green-blue (ARGB)
integers, to specify the beginning and ending colors of the stroke. Set this
property on the shape's options object by calling PolylineOptions.addSpan()
.
The following example shows creating a red to yellow gradient polyline from
Woodland Park Zoo to Kirkland, WA.
Java
Polyline line = map.addPolyline(new PolylineOptions() .add(new LatLng(47.6677146,-122.3470447), new LatLng(47.6442757,-122.2814693)) .addSpan(new StyleSpan(StrokeStyle.gradientBuilder(Color.RED, Color.YELLOW).build())));
Kotlin
val line = map.addPolyline( PolylineOptions() .add(LatLng(47.6677146, -122.3470447), LatLng(47.6442757, -122.2814693)) .addSpan( StyleSpan( StrokeStyle.gradientBuilder( Color.RED, Color.YELLOW ).build() ) ) )
Creating a stamped polyline
You can set the appearance of a polyline to a repeating bitmap texture. To do
this, create a StampStyle
of TextureStyle
, then set this property on the
shape's options object by calling PolylineOptions.addSpan()
as shown here:
Java
StampStyle stampStyle = TextureStyle.newBuilder(BitmapDescriptorFactory.fromResource(R.drawable.walking_dot)).build(); StyleSpan span = new StyleSpan(StrokeStyle.colorBuilder(Color.RED).stamp(stampStyle).build()); map.addPolyline(new PolylineOptions() .add(new LatLng(47.6677146,-122.3470447), new LatLng(47.6442757,-122.2814693)) .addSpan(span));
Kotlin
val stampStyle = TextureStyle.newBuilder(BitmapDescriptorFactory.fromResource(R.drawable.walking_dot)).build() val span = StyleSpan(StrokeStyle.colorBuilder(Color.RED).stamp(stampStyle).build()) map.addPolyline( PolylineOptions() .add(LatLng(47.6677146, -122.3470447), LatLng(47.6442757, -122.2814693)) .addSpan(span) )