【问题标题】:Cluster markers overlay by User's current location icon in AndroidAndroid中用户当前位置图标覆盖的集群标记
【发布时间】:2017-03-08 08:14:21
【问题描述】:

我正在使用在内部实现聚类标记的谷歌地图。但是,我的标记已被用户的当前位置图标覆盖,如下图

这是我的代码:

 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;
        }
    }

这是 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" />

我希望我的标记覆盖用户的当前位置图标。有人可以帮帮我吗?

【问题讨论】:

  • 我的位置图层绘制在地图顶部,因此您需要实现自己的位置图层以避免将其显示在顶部。看看stackoverflow.com/questions/33411112/…
  • 感谢您的快速回答。我仍然不知道如何将您的类实现到我的源代码中

标签: android google-maps google-maps-android-api-2 markerclusterer


【解决方案1】:

根据用户的标记,我假设您使用的是

mGoogleMap.setMyLocationEnbladed(true)

方法。

根据您的结果,我认为 googleMap 在集群标记之后绘制了 myLocation 标记。

也许解决方案是为 myLocation 绘制您的个人标记,因此,不要使用 setMyLocationEnabled() 方法,而是使用您自己的 onLocationChanged 方法标记。

我认为做你想做的事真的很难。正如我所说,GoogleMap 会在之前绘制标记。即使您在集群之前绘制 myLocation 标记,下一个 mylocation 也会在您的集群上方,因此您需要重新绘制集群。

另一种方法是使用 alpha(或透明度)绘制标记。

最后一件事,当用户在集群下时,为什么要隐藏用户的位置?

【讨论】:

  • 在使用drawable作为当前位置标记时,当集群与此类标记重叠时,集群单击不起作用。标记被点击。
【解决方案2】:

另一种方法是在 onDraw 中的 gmap 上绘制图层,这样您也可以在绘制位置图钉之前绘制位置标记。我很确定我早在 2013 年就做过类似的事情。抱歉没有留下任何代码,但这应该不难。

【讨论】:

    猜你喜欢
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-26
    • 1970-01-01
    相关资源
    最近更新 更多