Reputation: 179
I have the following problem, i add a couple of markers, 50% a black dot and 50% with a red dot as the icon, but 90% of them appear with the black dot.The ones that were supposed to be red change into red when i press on them and turn back in.WHY?
Thanks
P.S.Here is the code
mMap = mapFragment.getMap();
StationAccess stationAccess = new StationAccess(getApplicationContext());
List<Station> stationList = stationAccess.getByBusName(getTitle().toString());
if(s.getRouteType().toString().contains("TUR")){
mMap.addMarker(new MarkerOptions().position(new LatLng(s.getLatitude(),s.getLongitude())).title(s.getRouteType().toString()).icon(BitmapDescriptorFactory.fromResource(R.drawable.punct_negru)));
}
if(s.getRouteType().toString().contains("RETUR")){
mMap.addMarker(new MarkerOptions().position(new LatLng(s.getLatitude(),s.getLongitude())).title(s.getRouteType().toString()).icon(BitmapDescriptorFactory.fromResource(R.drawable.punct_rosu)));
}
Upvotes: 0
Views: 263
Reputation: 6380
This is because "RETUR" also contains the string "TUR". So any string of getRouteType that is true for the second if statement is also true for the first.
I would recommend not doing a string comparison on s.getRouteType(). I am unfamilar with your class structure but if it was an enumeration it could look something like
if (s.getRouteType().equals(RouteType.*Something*)) {
mMap.addMarker(new MarkerOptions().position(new LatLng(s.getLatitude(),s.getLongitude())).title(s.getRouteType().toString()).icon(BitmapDescriptorFactory.fromResource(R.drawable.punct_negru)));
} else if (s.getRouteType().equals(RouteType.*SomethingElse*)) {
mMap.addMarker(new MarkerOptions().position(new LatLng(s.getLatitude(),s.getLongitude())).title(s.getRouteType().toString()).icon(BitmapDescriptorFactory.fromResource(R.drawable.punct_rosu)));
}
Upvotes: 2