Cluster markers are superimposed on the icon of the user's current location in Android

I am using a google map that has a clustering marker built in. However, my markers were overlaid on the user's current location icon, as the image below enter 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 part of XML:

 <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 to display the user's current location icon. Can anybody help me?

+6
source share
2 answers

According to user token, I assume that you are using

 mGoogleMap.setMyLocationEnbladed(true) 

method.

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

Perhaps the solution is to draw your personal marker for myLocation and therefore do not use the setMyLocationEnabled () method, but your own marker with the onLocationChanged method.

It’s very hard for me to do what you want. As I said, GoogleMap draws a marker over the previous one. Even if you draw the myLocation marker in front of the clusters, the next mylocation will be above your cluster, so you will need to redraw the cluster.

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

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

+4
source

Another way would be to draw layers on gmaps in onDraw, so you could also draw a location marker just before drawing location contacts. I am pretty sure that I did something similar in 2013. Sorry, I don’t have the code, but it should not be difficult.

+1
source

Source: https://habr.com/ru/post/1015579/


All Articles