简体   繁体   English

如何使用xml布局作为集群标记Android

[英]how to use xml layout as cluster marker Android

I have a question, Is it possible to set a layout with multi imageviews and textviews as a cluster marker on the google map by android map utils? 我有一个问题,是否可以通过android map utils在Google地图上设置包含多个imageviews和textviews的布局作为聚类标记? and how? 如何? if somebody provide an good example it would be great this an example of what i want to do: 如果有人提供一个很好的例子,那就太好了,我想做的一个例子:

在此处输入图片说明

thanks 谢谢

I don't know if there is an easier way than what I used that was a year a go this method takes a lot of time if the data set is big so use it on small data set or talk to the designer for other options. 我不知道是否有比我一年前使用的方法简单的方法,如果数据集很大,则此方法会花费很多时间,因此请在较小的数据集上使用它,或与设计人员联系以寻求其他选择。

you can create a layout with what you want the get the bitmap of this layout this add the bitmap as a marker to the map since add marker only takes images. 您可以使用所需的布局创建布局,然后获取该布局的位图,这会将位图添加为地图的标记,因为添加标记仅拍摄图像。 *you need to set the data before creating the bitmap *创建位图之前需要设置数据

first step inflate and set data to your layout 第一步充气并设置数据到您的布局

View marker = ((LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.marker_layout, null);

second get the bitmap from this view 第二个从此视图获取位图

Bitmap bitmap = createDrawableFromView(
                                getActivity(), marker);

third add the bitmap as a marker 第三添加位图作为标记

   MarkerOptions mo = new MarkerOptions().position(
                                    new LatLng(lat, lng))
                                    // .title(address)
                                    .snippet(i + "")
                                    .icon(BitmapDescriptorFactory
                                            .fromBitmap(bitmap));
                            Marker customMarker = googleMap.addMarker(mo);

this is how to get the bitmap 这是获取位图的方法

public static Bitmap createDrawableFromView(Context context, View view) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    if (context != null) {
        ((Activity) context).getWindowManager().getDefaultDisplay()
                .getMetrics(displayMetrics);
        view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
        view.layout(0, 0, displayMetrics.widthPixels,
                displayMetrics.heightPixels);
        view.buildDrawingCache();
        Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(),
                view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(bitmap);
        view.draw(canvas);
        return bitmap;
    }
    return null;
}

goodluck with that it was a lot of pain. 祝你好运,这是非常痛苦的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM