【问题标题】:Changing the marker icon using android-maps-extensions使用 android-maps-extensions 更改标记图标
【发布时间】:2013-08-07 13:33:42
【问题描述】:

我搬到android-maps-extensions 进行集群。但我想在运行时更改标记的图标。在原始的谷歌地图库标记中有一个setIcon 方法,扩展库中缺少该方法。将方法添加到 Marker 实现是否可行,或者我应该寻找另一种解决方法,例如删除标记并添加新标记而不是更改图标?

【问题讨论】:

    标签: android google-maps-markers android-maps-extensions


    【解决方案1】:

    1.3.1版本可以直接从项目站点下载,没有添加setIcon

    当前状态是1.4版即将发布,包括setIconsetAnchor。我在将 zip 文件上传到 code.google.com 时遇到了一些问题。

    如果您不想使用 git 克隆存储库,可以从 GitHub 存储库获取最新版本:https://github.com/mg6maciej/android-maps-extensions/archive/master.zip

    请注意,setIcon 仅适用于您添加到地图的 Markers。您暂时无法通过这种方式更改集群图标。

    编辑:

    ClusterMarker.setIcon 代码从

    @Override
    public void setIcon(BitmapDescriptor icon) {
        throw new UnsupportedOperationException();
    }
    

    类似于:

    @Override
    public void setIcon(BitmapDescriptor icon) {
        if (virtual != null) {
            virtual.setIcon(icon);
        }
    }
    

    在大多数情况下应该可以工作。

    【讨论】:

    • 有效。知道如何为集群标记实现这一点吗?也许IconDataProvider 可以用于那个?
    • @comatic 取决于您想要更改图标的时间。如果是在集群 Marker 创建之后,请查看我的编辑。
    【解决方案2】:

    如果要实现自定义聚类图标

    这样做..........

    for (Cluster cluster : clusterList) {
    
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inMutable = true;
        options.inPurgeable = true;
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.cluster_marker, options);
    
        Canvas canvas = new Canvas(bitmap);
    
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.white));
        paint.setTextSize(30);
    
        canvas.drawText(String.valueOf(cluster.getMarkerList().size()), 10,
                40, paint);
    
        googleMap.addMarker(new MarkerOptions()
                .position(
                        new LatLng(cluster.getClusterLatitude(), cluster
                                .getClusterLongitude()))
                .snippet(String.valueOf(cluster.getMarkerList().size()))
                .title("Cluster")
                .icon(BitmapDescriptorFactory.fromBitmap(bitmap)));
    
    }
    

    集群标记是我的可绘制对象,我在上面写文字。

    【讨论】:

      猜你喜欢
      • 2015-11-23
      • 2015-08-30
      • 2013-08-31
      • 2016-03-11
      • 1970-01-01
      • 2020-03-12
      • 2014-01-25
      • 2016-12-25
      • 2013-05-31
      相关资源
      最近更新 更多