简体   繁体   中英

android Google maps marker problme

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

PSHere 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)));
            }

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

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