简体   繁体   English

Android Google Maps Marker问题

[英]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? 我有以下问题,我添加了几个标记,其中50%的黑点和50%的红点作为图标,但是其中90%的黑点出现了。当我按下它们并重新打开时显示为红色。为什么?

Thanks 谢谢

PSHere is the code PS这是代码

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". 这是因为“ RETUR”还包含字符串“ TUR”。 So any string of getRouteType that is true for the second if statement is also true for the first. 因此,对于第二个if语句为true的任何getRouteType字符串,对于第一个if语句也为true。

I would recommend not doing a string comparison on s.getRouteType(). 我建议不要在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)));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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