2

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. I want each marker to have a circle around it. IS there any way in Android maps Extension library to achieve this ?

This is when clustered when clustered

When Cluster Rendered current behavior

When rendered cluster this is the current behavior

Desired behavior

Desired behavior

Akshay
  • 833
  • 2
  • 16
  • 34

2 Answers2

1

I think this library for clustering can help you. Android Maps Extensions https://github.com/mg6maciej/android-maps-extensions

Android Get the markers that are not clustered

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.

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)

// 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)));
Community
  • 1
  • 1
Stas Parshin
  • 7,973
  • 3
  • 24
  • 43
  • is there any way in this library to add circles on markers and remove those circles when markers are reclustered ? – Akshay Aug 05 '15 at 17:52
  • I can can not use the png image because the radius of my circle varies. – Akshay Aug 05 '15 at 19:06
  • have you used this library before? I was trying to integrate it now and I am getting map as null when I do map = mapFragment.getExtendedMap(); and I verified my mapFragment is not null. This is how I am creating mapFragment mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container); if (mapFragment == null) { mapFragment = SupportMapFragment.newInstance(); FragmentTransaction tx = fm.beginTransaction(); tx.add(R.id.map_container, mapFragment); tx.commit(); } – Akshay Aug 05 '15 at 20:38
  • Yes, I'm using it and it's good. You should take map by async method mapFragment.getExtendedMapAsync(new OnMapReadyCallback() { public void onMapReady(GoogleMap googleMap) { mMap = googleMap; setUpMap(); } }); – Stas Parshin Aug 05 '15 at 20:50
  • @Akshay but you can use my last solution with circle in pure google maps, you don't need this library for that – Stas Parshin Aug 05 '15 at 20:51
  • but How can I cluster the markers then .because I have to set around 10K markers on the map. When I try to launch map it gives StackOverflow Error because of so many markers. So I need Clustering – Akshay Aug 05 '15 at 20:53
  • @Akshay for clustering you can use Google Maps Android API Utility or Android Maps Extensions, what you like more. But as I understand, this thread is about circle drawing. Is this problem solved? – Stas Parshin Aug 05 '15 at 21:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/85242/discussion-between-akshay-and-pengrad). – Akshay Aug 05 '15 at 21:04
0

Google maps now has an API for drawing a circle you can use it combined with a simple marker, it should do the same effect

M_AWADI
  • 4,086
  • 1
  • 18
  • 12