Java 如何基于当前地图过滤器和标记的HashMap字符串组合设置Google Maps标记图标

Java 如何基于当前地图过滤器和标记的HashMap字符串组合设置Google Maps标记图标,java,icons,hashmap,google-maps-markers,android-maps-v2,Java,Icons,Hashmap,Google Maps Markers,Android Maps V2,如果有人对实现基于以下内容设置地图标记图标的代码的最有效方法有任何建议,这将非常有用: 由用户定义的过滤器,指示要显示的标记(布尔值) 包含在与标记关联的HashMap中的键-inclass CrimePoint 筛选用户定义的选项: boolean displayAntiSocialBehaviourMarkers; boolean displayBurglaryMarkers; boolean displayCriminalDamageArsonMarkers;

如果有人对实现基于以下内容设置地图标记图标的代码的最有效方法有任何建议,这将非常有用:

  • 由用户定义的过滤器,指示要显示的标记(
    布尔值
  • 包含在与标记关联的
    HashMap
    中的键-in
    class CrimePoint
筛选用户定义的选项:

    boolean displayAntiSocialBehaviourMarkers;
    boolean displayBurglaryMarkers;
    boolean displayCriminalDamageArsonMarkers;
    boolean displayDrugsMarkers;
    boolean displayOtherTheftMarkers;
    boolean displayPubDisorderWeaponsMarkers;
    boolean displayRobberyMarkers;
    boolean displayShopliftingMarkers;
    boolean displayVehicleCrimeMarkers;
    boolean displayViolentCrimeMarkers;
    boolean displayOtherCrimeMarkers;
private final Double latitude;
private final Double longitude;
private final String title;

//SNIPPET
//The HashMap storing the categories associated with this CrimePoint.
//Category name is the key and the number of crimes in that category is the Value
//
private Map<String, Integer> crimeCategories;

//An integer to hold the references to the icon image to use
//Example: R.drawable.image002;
private int iconResource;
每个标记都使用
CrimePoint
创建,该类包含绘制标记所需的所有信息

犯罪点类变量:

    boolean displayAntiSocialBehaviourMarkers;
    boolean displayBurglaryMarkers;
    boolean displayCriminalDamageArsonMarkers;
    boolean displayDrugsMarkers;
    boolean displayOtherTheftMarkers;
    boolean displayPubDisorderWeaponsMarkers;
    boolean displayRobberyMarkers;
    boolean displayShopliftingMarkers;
    boolean displayVehicleCrimeMarkers;
    boolean displayViolentCrimeMarkers;
    boolean displayOtherCrimeMarkers;
private final Double latitude;
private final Double longitude;
private final String title;

//SNIPPET
//The HashMap storing the categories associated with this CrimePoint.
//Category name is the key and the number of crimes in that category is the Value
//
private Map<String, Integer> crimeCategories;

//An integer to hold the references to the icon image to use
//Example: R.drawable.image002;
private int iconResource;
私人最终双纬度;
私人最终双经度;
私人最终字符串标题;
//片段
//存储与此犯罪点关联的类别的哈希映射。
//类别名称是键,该类别中的犯罪数量是值
//
私人地图犯罪分类;
//一个整数,用于保存对要使用的图标图像的引用
//示例:R.drawable.image002;
私人互联网资源;
标记图标:

    boolean displayAntiSocialBehaviourMarkers;
    boolean displayBurglaryMarkers;
    boolean displayCriminalDamageArsonMarkers;
    boolean displayDrugsMarkers;
    boolean displayOtherTheftMarkers;
    boolean displayPubDisorderWeaponsMarkers;
    boolean displayRobberyMarkers;
    boolean displayShopliftingMarkers;
    boolean displayVehicleCrimeMarkers;
    boolean displayViolentCrimeMarkers;
    boolean displayOtherCrimeMarkers;
private final Double latitude;
private final Double longitude;
private final String title;

//SNIPPET
//The HashMap storing the categories associated with this CrimePoint.
//Category name is the key and the number of crimes in that category is the Value
//
private Map<String, Integer> crimeCategories;

//An integer to hold the references to the icon image to use
//Example: R.drawable.image002;
private int iconResource;
地图上有12个不同的标记图标。每个过滤器选项[如上所述]一个,一个特殊案例标记(多重犯罪),其中:
-
CrimePoint
有多个犯罪类别(
crimeCategories.size()>1

-使用过滤器选项将
CrimePoint
中包含的多个犯罪类别设置为可见

仅当显示一个(或多个)犯罪类别时,才会绘制标记

任何帮助或建议都会很好,因为我花了很长时间来处理我需要的逻辑,但还没有想出多少


注意:每次过滤选项被用户更改时,都需要调用这个函数来改变地图上的图标和隐藏/显示标记。

首先,你应该考虑改变你的表示方式。从列举犯罪类型开始:

enum CrimeType { AntiSocialBehaviour, ..., Count }
现在可以将您的标志创建为枚举集:

EnumSet<CrimeType> showMarkers = new EnumSet<CrimeType>();
EnumSet showmarks=new EnumSet();
这与常规Java
集合类似,但效率更高。如果不需要散列的功能,则在标记中使用它们,而不是在散列中使用它们

要打开和关闭标记,请注意。更改过滤器标志时,遍历标记列表以适当设置可见性。然后使地图片段或视图无效。绘图时间将主导可见性设置时间,因此这是最有效的

我从关于效率的问题中推断出你们有很多标记。如果有太多的标记,以致地图因重叠而变得混乱,则必须实现合并算法以用一个标记表示多个标记。我早些时候发布了关于这个主题的帖子,但没有收到任何回复。我的解决方案解释说,虽然没有我希望的那么快(Nexus平板电脑上有大约15000个标记,只需2-3秒),但效果相当好

对于非标准标记外观,请进行研究


这很清楚。如果您有特定的问题并显示代码,我们可以提供详细帮助。

我们讨论的是本机API而不是javascript?是的,在Eclipse中的
GoogleMap
对象上。不是javascript:)嗨,我考虑过对犯罪类型使用枚举,因为字符串总是一样的。但是,我不太熟悉使用enum和犯罪点列表&它们的关联类别是通过运行一系列jsonobject创建或更新一个新的犯罪点而形成的。我对枚举进行了折扣,因为我需要为类别指定一个值,在运行JSON时,该值可能会发生变化。关于可见性,我知道有一个设置可以传递给标记器;目前,这只是背后的逻辑。我正在考虑一个额外的领域。。。(开或关)必须在选择图标的同时进行配置
犯罪点的数量可以从
0
到大约
4000
不等,但我的代码目前将其中一些分组,因为它们可能发生在同一位置。然而,你是正确的,我的地图看起来杂乱无章,有太多的“数据”供用户解释。我本来打算实现一个合并,比如“MarkerClusterer”,所以我一定会读这篇文章:)。花时间了解Enum可能是值得的。它们很灵活。每个枚举值本质上是一个隐式父类的实例,它可以定义数据实例值和成员函数。看,有趣的是,我之前读过。我们刚刚实现了一个枚举,如下所示,一旦实现了它,应该会更容易:
公共枚举犯罪分类{ASBO(“反社会行为”),…私有字符串分类;犯罪分类(字符串分类){this.category=category;}