6

I'm using google map that implemented Clustering marker inside. However, my markers has been overlaid by User's current location icon like Image belowenter image description here

this is my code:

 protected void onBeforeClusterRendered(Cluster<CurationLocation> cluster, MarkerOptions markerOptions) {
        if (isAdded()) {
            final Drawable clusterIcon = getResources().getDrawable(R.drawable.oval_bg);
            mClusterIconGenerator.setBackground(clusterIcon);
            mClusterIconGenerator.setTextAppearance(R.style.AppTheme_WhiteTextAppearance);

            LayoutInflater myInflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View clusterView = myInflater.inflate(R.layout.customize_cluster_layout, null, false);
            mClusterIconGenerator.setContentView(clusterView);

            final Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
            markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
        } else {
            return;
        }
    }

this is XML part:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:weightSum="1">

<TextView
    android:id="@+id/text"
    android:layout_width="30dp"
    android:layout_height="40dp"
    android:background="@drawable/icon_location_clustering"
    android:gravity="center_horizontal"
    android:paddingTop="5dp"
    android:text="33"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#000000"
    android:textSize="13sp" />

I want my markers should overlay User's current location icon. Can anybody help me?

Aryan Najafi
  • 2,496
  • 27
  • 29
TranHieu
  • 914
  • 6
  • 23
  • The My Location layer draws on top of the map, so you will need to implement your own location layer to avoid showing it on top. Take a look at http://stackoverflow.com/questions/33411112/change-custom-current-location-indicator-in-google-map-v2/33417474#33417474 – antonio Mar 08 '17 at 08:20
  • I appreciate your quick answer. I still dont know how can I implement your class into my source code – TranHieu Mar 08 '17 at 08:33

2 Answers2

4

According to the user's marker, I am assuming you use the

mGoogleMap.setMyLocationEnbladed(true)

method.

According to your result, I think that googleMap draws the myLocation marker after the cluster markers.

Maybe the solution is to draw your personnal marker for myLocation and so, don't use the setMyLocationEnabled() method but your own marker with onLocationChanged method.

I think it's really hard to do what you want. As I said, GoogleMap draws marker over the previous. Even if you draw the myLocation marker before the clusters, the next mylocation will be over your cluster, so you'll need to redraw your cluster.

Another approach could be to draw markers with alpha (or transparency).

Last thing, why do you want to hide the user's location when he is below a cluster ?

Cocorico
  • 1,998
  • 1
  • 22
  • 38
  • 1
    While using drawable for current location marker, when Cluster is overlapping such marker, cluster click is not working. marker getting clicked. – Jaimin Modi Dec 19 '17 at 07:00
1

The other way would be to draw layers on gmaps in onDraw, that way you might also draw location marker just before drawing the location pins. I'm pretty sure I did something like this back in 2013. Sorry don't have any code left, but it shouldn't be hard.

Kirill Volkov
  • 942
  • 1
  • 9
  • 18