目前我正在使用 Google Maps Android API Utility 进行集群,但我没有找到在标记从集群中可见/呈现时在标记周围添加圆圈的方法。我希望每个标记都有一个圆圈。 Android map 扩展库中有什么方法可以实现这一点吗?
当集群渲染当前行为
期望的行为
最佳答案
我认为这个用于聚类的库可以帮助您。 Android map 扩展 https://github.com/mg6maciej/android-maps-extensions
Android Get the markers that are not clustered
如果您只需要更改标记的图标,您可以制作 png 图像(例如,带有默认标记图标和圆圈)并将其作为资源粘贴到标记。
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_circle)));
如果您需要自定义圆圈,您可以通过编程方式创建它,但您仍然需要自定义标记图标(当然还需要提供不同版本(hdpi、xhdpi ...)以调整大小)
// circle
int diameter = 500;
Bitmap bm = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.A
Canvas canvas = new Canvas(bm);
Paint p = new Paint();
p.setColor(getResources().getColor(R.color.green));
canvas.drawCircle(diameter / 2, diameter / 2, diameter / 2, p);
// marker icon through Drawable
Drawable drawable = getResources().getDrawable(R.drawable.marker_icon, null);
// you should choose bounds
// drawable.setBounds(left, top, right, bottom);
drawable.draw(canvas);
//OR marker icon through Bitmap
Bitmap bmIcon = BitmapFactory.decodeResource(getResources(), R.drawable.marker_icon);
// choose correct top and left margin
canvas.drawBitmap(bmIcon, diameter / 2, diameter / 2, p);
map.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(bm)));
关于java - 当标记变得可见时,在标记周围添加一个圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31838224/