群集标记由用户在Android中的当前位置图标重叠 [英] Cluster markers overlay by User's current location icon in Android

查看:84
本文介绍了群集标记由用户在Android中的当前位置图标重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



这是我的代码:

  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);
查看clusterView = myInflater.inflate(R.layout.customize_cluster_layout,null,false);
mClusterIconGenerator.setContentView(clusterView);

最终位图图标= 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_centerHorizo​​ntal =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_horizo​​ntal
android:paddingTop =5dp
android:text =33
android :textAppearance =?android:attr / textAppearanceMedium
android:textColor =#000000
android:textSize =13sp/>



我希望我的标记覆盖用户的当前位置图标。任何人都可以帮助我?

解决方案

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

  mGoogleMap.setMyLocationEnbladed(true)

方法。

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



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



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

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

最后,为什么要隐藏用户的位置?

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

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?

解决方案

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 ?

这篇关于群集标记由用户在Android中的当前位置图标重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆