简体   繁体   中英

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]);

        }
}

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM