简体   繁体   English

当标记变得可见时,在标记周围添加一个圆圈

[英]Add a circle around the marker, when marker becomes visible

Currently I am using Google Maps Android API Utility for clustering, but I didn't find the way to add a circle around the marker when it becomes visible/rendered from the cluster.目前,我正在使用 Google Maps Android API Utility 进行集群,但是当标记从集群可见/呈现时,我没有找到在标记周围添加圆圈的方法。 I want each marker to have a circle around it.我希望每个标记周围都有一个圆圈。 IS there any way in Android maps Extension library to achieve this ? Android 地图扩展库中有什么方法可以实现这一点吗?

This is when clustered这是集群时聚集时

When Cluster Rendered current behavior当集群呈现当前行为时

渲染集群时,这是当前行为

Desired behavior期望的行为

期望的行为

I think this library for clustering can help you.我认为这个用于聚类的库可以帮助你。 Android Maps Extensions https://github.com/mg6maciej/android-maps-extensions Android 地图扩展https://github.com/mg6maciej/android-maps-extensions

Android Get the markers that are not clustered Android 获取未聚类的标记

If you just need to change marker's icon, you can make png-image (for example, with default marker icon and circle) and paste it to marker as resource.如果您只需要更改标记的图标,您可以制作 png-image(例如,使用默认标记图标和圆圈)并将其粘贴到标记作为资源。

map.addMarker(new MarkerOptions()
     .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_circle)));

If you need custom circle, you create it programmatically, but you still need custom marker icon (and of course provide different versions (hdpi, xhdpi...) for resize)如果您需要自定义圆圈,您可以通过编程方式创建它,但您仍然需要自定义标记图标(当然还需要提供不同版本(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)));

谷歌地图现在有一个绘制圆API,你可以将它与一个简单的标记结合使用,它应该有同样的效果

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

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