RoktSe
RoktSe

Reputation: 469

Add polyline to google maps with different colors android

I'm trying to get coordinates from Firebase to create polyline on Google maps with different colors to each user. The problem is when I get this data and insert it on google maps it shows with the same color.

List<Integer> colors = new ArrayList<>();
colors.add(-9784993);
colors.add(-6501807);

for (int a = 0; a <= userList.size()-1; i++) {

     for (DataSnapshot objSnapshot : dataSnapshot.getChildren()) {

          dataClass d = objSnapshot.getValue(dataClass.class);

          LatLng start = new LatLng(d.getLat(), d.getLongi());

          elasticList.add(start);

          polylineOptionsTest[a] = new PolylineOptions()
               .addAll(elasticList)
               .color(colors.get(a)) //Get color from list called "colors"
               .clickable(true);
          polyline2 = mMap.addPolyline(polylineOptionsTest[a]);

        }
}

Upvotes: 0

Views: 118

Answers (1)

Andrii Omelchenko
Andrii Omelchenko

Reputation: 13343

Probably that is because userList.size() is equals 1 and colors.get(a) always returns colors[0] (-9784993) color. In other words you add polylines for single user.

Update: mistake is in for loop - you should use:

for (int a = 0; a <= userList.size()-1; a++) {

instead of

for (int a = 0; a <= userList.size()-1; i++) {

you increase i variable, not a.

Upvotes: 1

Related Questions