I'm using this code to display a driving route on a google map. the problem is that whenever i want to add multiple polylines with different colors, i get all the polylines with the same color which is the last one in the for loop used.
public void requestDirection(final LatLng nUserCurrentLoc, final LatLng objectiveLatLng) {
Toast.makeText(getBaseContext(), "Requesting direction, just a moment...", Toast.LENGTH_SHORT).show();
GoogleDirection.withServerKey(SERVER_API_KEY)
.from(nUserCurrentLoc)
.to(objectiveLatLng)
.transportMode(TransportMode.DRIVING)
.execute(this);
uiHandler.postDelayed(new Runnable() {
@Override
public void run() {
positionCamera(nUserCurrentLoc, objectiveLatLng);
}
}, 2800);
}
@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
if (direction.isOK()) {
Toast.makeText(getBaseContext(), "Routes are marked successfully...", Toast.LENGTH_SHORT).show();
final ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint();
int zzzz = -16711681;
for(int i =0; i<colorList.size(); i++){
String pls = (String)colorList.get(i);
if (pls.equals("BLUE")) zzzz = -16711681;
else if (pls.equals("RED")) zzzz = -65281;
else if (pls.equals("GREEN")) zzzz = -256;
else if (pls.equals("BLACK")) zzzz = -7829368;
else if (pls.equals("DKGRAY")) zzzz = -3355444;
itineraryLines = mMap.addPolyline(DirectionConverter.createPolyline(getApplicationContext(),
directionPositionList, 5, zzzz));
}
}else {
Toast.makeText(getBaseContext(), "Routes are suspicious!", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onDirectionFailure(Throwable t) {
Toast.makeText(getBaseContext(), "No routes found!", Toast.LENGTH_SHORT).show();
}
colorList contains BLACK and GREEN, but when the routes are displayed i get them both with the color relative to GREEN ( i tried multiple combination, i always get the last loop's color). Any ideas how to solve this ?
DirectionConverterclass?