Ralf Wickum
Ralf Wickum

Reputation: 3270

API Level for Google Maps Interactive Polylines?

I use interactive Polylines to highlight calculated routes from Google Maps:

As you can see here and here I get a base64 String which I then fed to:

if (!TextUtils.isEmpty(stringPolyline)) {
    List<LatLng> latLngList = PolyUtil.decode(stringPolyline);

    PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.addAll(latLngList);
    polylineOptions.color(Color.RED);

    Polyline polyline = googleMap.addPolyline(polylineOptions);
}

On my devices with Android 6 & 7 it works perfectly. But I have a device with Android 4.4.4 for an example. There I don't see those very same polylines.

How can I make the polylines visible on my Android 4.4 devices?

Upvotes: 2

Views: 281

Answers (1)

nano
nano

Reputation: 2521

Instead of using one single polyline with multiple locations, try to paint several lines:

List<LatLng> latLngList = PolyUtil.decode(stringPolyline);

if (googleMap != null && latLngList.size() > 1) {
    for (int i = 0; i < latLngList .size() - 1; i++) {
        LatLng src = latLngList.get(i);
        LatLng dest = latLngList.get(i + 1);

        Polyline polyline = googleMap.addPolyline(
            new PolylineOptions().add(
                new LatLng(src.latitude, src.longitude),
                new LatLng(dest.latitude,dest.longitude)
            ).width(5).color(Color.RED).geodesic(true)
        );
    }
}

Upvotes: 3

Related Questions