Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌地图标记被缩放时的边框替换_Android_Google Maps_Google Play Services - Fatal编程技术网

Android 谷歌地图标记被缩放时的边框替换

Android 谷歌地图标记被缩放时的边框替换,android,google-maps,google-play-services,Android,Google Maps,Google Play Services,我在片段内部和最近使用SupportMapFragment进行集群。Google Play服务更新至9.0.83后,Google单一地图标记将被缩放时的边框所取代。只替换单个标记,簇标记可以。更改应用程序清单中的硬件加速参数不会更改任何内容。如何修复它 附言 根据tyczj的说法,当Google Play服务(专有二进制文件)更新到9.0.x时,这种情况就开始发生了 从Github问题讨论的外观来看,解决方法是: 从gmaps api问题页面查找可能的工作区域: 改变 setIcon(Bitm

我在片段内部和最近使用SupportMapFragment进行集群。Google Play服务更新至9.0.83后,Google单一地图标记将被缩放时的边框所取代。只替换单个标记,簇标记可以。更改应用程序清单中的硬件加速参数不会更改任何内容。如何修复它

附言


根据tyczj的说法,当Google Play服务(专有二进制文件)更新到9.0.x时,这种情况就开始发生了

从Github问题讨论的外观来看,解决方法是:

从gmaps api问题页面查找可能的工作区域:

改变 setIcon(BitmapDescriptorFactory.fromResource(R.drawable.drawableid))

到 marker.setIcon(BitmapDescriptorFactory.fromBitmap)(BitmapFactory.decodeResource(getResources()), R.drawable.drawableid))//可能会影响一般内存消耗 tho(?),我测试的应用程序没有超过 问题

还注意到:

我可以证实这个问题。除了@Mavamaarten,您不能 重用标记图像


(来源:)

我使用简化版的@bishop87解决方案。还为集群位图添加了缓存,这使其更加安全

如果没有群集渲染器,请使用此渲染器或将此代码移到自己的渲染器:

SimpleClusterRenderer.java

public class SimpleClusterRenderer extends DefaultClusterRenderer<AuctionItem> {
    private static final int CLUSTER_PADDING = 12;
    private static final int ITEM_PADDING = 7;

    private final Bitmap mIconItemGreen;
    private final IconGenerator mIconClusterGenerator;
    private final float mDensity;

    public SimpleClusterRenderer(Context context, GoogleMap map, ClusterManager<AuctionItem> clusterManager) {
        super(context, map, clusterManager);

        mDensity = context.getResources().getDisplayMetrics().density;

        mIconClusterGenerator = new CachedIconGenerator(context);
        mIconClusterGenerator.setContentView(makeSquareTextView(context, CLUSTER_PADDING));
        mIconClusterGenerator.setTextAppearance(com.google.maps.android.R.style.ClusterIcon_TextAppearance);

        IconGenerator iconItemGenerator = new IconGenerator(context);
        iconItemGenerator.setContentView(makeSquareTextView(context, ITEM_PADDING));
        iconItemGenerator.setBackground(makeClusterBackground(ContextCompat.getColor(context, R.color.simple_green)));
        mIconItemGreen = iconItemGenerator.makeIcon();
    }

    @Override
    protected void onBeforeClusterItemRendered(AuctionItem item, MarkerOptions markerOptions) {
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(mIconItemGreen));
    }

    @Override
    protected void onBeforeClusterRendered(Cluster<AuctionItem> cluster, MarkerOptions markerOptions) {
        int clusterSize = getBucket(cluster);

        mIconClusterGenerator.setBackground(makeClusterBackground(getColor(clusterSize)));
        BitmapDescriptor descriptor = BitmapDescriptorFactory.fromBitmap(mIconClusterGenerator.makeIcon(getClusterText(clusterSize)));
        markerOptions.icon(descriptor);
    }

    @Override
    protected boolean shouldRenderAsCluster(Cluster<AuctionItem> cluster) {
        // Always render clusters.
        return cluster.getSize() > 1;
    }

    private int getColor(int clusterSize) {
        float size = Math.min((float) clusterSize, 300.0F);
        float hue = (300.0F - size) * (300.0F - size) / 90000.0F * 220.0F;
        return Color.HSVToColor(new float[]{hue, 1.0F, 0.6F});
    }

    private LayerDrawable makeClusterBackground(int color) {
        ShapeDrawable mColoredCircleBackground = new ShapeDrawable(new OvalShape());
        mColoredCircleBackground.getPaint().setColor(color);
        ShapeDrawable outline = new ShapeDrawable(new OvalShape());
        outline.getPaint().setColor(0x80ffffff);
        LayerDrawable background = new LayerDrawable(new Drawable[]{outline, mColoredCircleBackground});
        int strokeWidth = (int) (mDensity * 3.0F);
        background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
        return background;
    }

    private SquareTextView makeSquareTextView(Context context, int padding) {
        SquareTextView squareTextView = new SquareTextView(context);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        squareTextView.setLayoutParams(layoutParams);
        squareTextView.setId(R.id.text);
        int paddingDpi = (int) (padding * mDensity);
        squareTextView.setPadding(paddingDpi, paddingDpi, paddingDpi, paddingDpi);
        return squareTextView;
    }
}
public class CachedIconGenerator extends IconGenerator {

    private final LruCache<String, Bitmap> mBitmapsCache;
    private String mText;

    public CachedIconGenerator(Context context) {
        super(context);

        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = maxMemory / 8;
        mBitmapsCache = new LruCache<String, Bitmap>(cacheSize) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                // The cache size will be measured in kilobytes rather than
                // number of items.
                return bitmap.getByteCount() / 1024;
            }
        };
    }

    public Bitmap makeIcon(String text) {
        mText = text;
        return super.makeIcon(text);
    }

    @Override
    public Bitmap makeIcon() {
        if (TextUtils.isEmpty(mText)) {
            return super.makeIcon();
        } else {
            Bitmap bitmap = mBitmapsCache.get(mText);
            if (bitmap == null) {
                bitmap = super.makeIcon();
                mBitmapsCache.put(mText, bitmap);
            }
            return bitmap;
        }
    }
}
公共类SimpleClusterRenderer扩展了DefaultClusterRenderer{
私有静态最终int集群_PADDING=12;
私有静态最终整数项_PADDING=7;
米康涅姆格林私人酒店;
专用最终IconGenerator mIconClusterGenerator;
私人最终浮动密度;
公共SimpleClusterRenderer(上下文上下文、Google地图、ClusterManager ClusterManager){
超级(上下文、地图、群集管理器);
mDensity=context.getResources().getDisplayMetrics().density;
mIconClusterGenerator=新的CachedIconGenerator(上下文);
setContentView(makeSquareTextView(上下文,集群填充));
mIconClusterGenerator.setTextAppearance(com.google.maps.android.R.style.ClusterIcon\u TextAppearance);
IconGenerator iconItemGenerator=新IconGenerator(上下文);
setContentView(makeSquareTextView(上下文,项填充));
setBackground(makeClusterBackground(ContextCompat.getColor(context,R.color.simple_green));
mIconItemGreen=iconItemGenerator.makeIcon();
}
@凌驾
PreforeClusterItemRendered上的受保护无效(AuctionItem项目、MarkeOptions MarkeOptions){
图标(BitmapDescriptorFactory.fromBitmap(miconitMgreen));
}
@凌驾
在呈现群集之前受保护的void(群集群集、标记选项标记选项){
int clusterSize=getBucket(集群);
setBackground(makeClusterBackground(getColor(clusterSize)));
BitmapDescriptor descriptor=BitmapDescriptorFactory.fromBitmap(mIconClusterGenerator.makeIcon(getClusterText(clusterSize));
标记选项。图标(描述符);
}
@凌驾
受保护的布尔值shouldRenderAsCluster(群集){
//始终渲染群集。
返回cluster.getSize()>1;
}
私有int getColor(int clusterSize){
浮动大小=数学最小值((浮动)群集大小,300.0F);
浮动色调=(300.0F-尺寸)*(300.0F-尺寸)/90000.0F*220.0F;
返回颜色.HSVToColor(新的浮点[]{hue,1.0F,0.6F});
}
私有层可绘制makeClusterBackground(int颜色){
ShapeDrawable mColoredCircleBackground=新的ShapeDrawable(新的卵形());
mColoredCircleBackground.getPaint().setColor(颜色);
ShapeDrawable outline=新的ShapeDrawable(新的卵形());
outline.getPaint().setColor(0x80ffffff);
LayerDrawable background=新的LayerDrawable(新的Drawable[]{大纲,mColoredCircleBackground});
int strokeWidth=(int)(密度*3.0F);
背景。SetLayerSet(1,strokeWidth,strokeWidth,strokeWidth,strokeWidth);
返回背景;
}
私有SquareTextView makeSquareTextView(上下文上下文,整数填充){
SquareTextView SquareTextView=新的SquareTextView(上下文);
ViewGroup.LayoutParams LayoutParams=新建ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容);
squareTextView.setLayoutParams(layoutParams);
squareTextView.setId(R.id.text);
int paddingDpi=(int)(padding*mDensity);
设置填充(填充DPI,填充DPI,填充DPI,填充DPI,填充DPI);
返回squareTextView;
}
}
CachedIconGenerator.java

public class SimpleClusterRenderer extends DefaultClusterRenderer<AuctionItem> {
    private static final int CLUSTER_PADDING = 12;
    private static final int ITEM_PADDING = 7;

    private final Bitmap mIconItemGreen;
    private final IconGenerator mIconClusterGenerator;
    private final float mDensity;

    public SimpleClusterRenderer(Context context, GoogleMap map, ClusterManager<AuctionItem> clusterManager) {
        super(context, map, clusterManager);

        mDensity = context.getResources().getDisplayMetrics().density;

        mIconClusterGenerator = new CachedIconGenerator(context);
        mIconClusterGenerator.setContentView(makeSquareTextView(context, CLUSTER_PADDING));
        mIconClusterGenerator.setTextAppearance(com.google.maps.android.R.style.ClusterIcon_TextAppearance);

        IconGenerator iconItemGenerator = new IconGenerator(context);
        iconItemGenerator.setContentView(makeSquareTextView(context, ITEM_PADDING));
        iconItemGenerator.setBackground(makeClusterBackground(ContextCompat.getColor(context, R.color.simple_green)));
        mIconItemGreen = iconItemGenerator.makeIcon();
    }

    @Override
    protected void onBeforeClusterItemRendered(AuctionItem item, MarkerOptions markerOptions) {
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(mIconItemGreen));
    }

    @Override
    protected void onBeforeClusterRendered(Cluster<AuctionItem> cluster, MarkerOptions markerOptions) {
        int clusterSize = getBucket(cluster);

        mIconClusterGenerator.setBackground(makeClusterBackground(getColor(clusterSize)));
        BitmapDescriptor descriptor = BitmapDescriptorFactory.fromBitmap(mIconClusterGenerator.makeIcon(getClusterText(clusterSize)));
        markerOptions.icon(descriptor);
    }

    @Override
    protected boolean shouldRenderAsCluster(Cluster<AuctionItem> cluster) {
        // Always render clusters.
        return cluster.getSize() > 1;
    }

    private int getColor(int clusterSize) {
        float size = Math.min((float) clusterSize, 300.0F);
        float hue = (300.0F - size) * (300.0F - size) / 90000.0F * 220.0F;
        return Color.HSVToColor(new float[]{hue, 1.0F, 0.6F});
    }

    private LayerDrawable makeClusterBackground(int color) {
        ShapeDrawable mColoredCircleBackground = new ShapeDrawable(new OvalShape());
        mColoredCircleBackground.getPaint().setColor(color);
        ShapeDrawable outline = new ShapeDrawable(new OvalShape());
        outline.getPaint().setColor(0x80ffffff);
        LayerDrawable background = new LayerDrawable(new Drawable[]{outline, mColoredCircleBackground});
        int strokeWidth = (int) (mDensity * 3.0F);
        background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
        return background;
    }

    private SquareTextView makeSquareTextView(Context context, int padding) {
        SquareTextView squareTextView = new SquareTextView(context);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        squareTextView.setLayoutParams(layoutParams);
        squareTextView.setId(R.id.text);
        int paddingDpi = (int) (padding * mDensity);
        squareTextView.setPadding(paddingDpi, paddingDpi, paddingDpi, paddingDpi);
        return squareTextView;
    }
}
public class CachedIconGenerator extends IconGenerator {

    private final LruCache<String, Bitmap> mBitmapsCache;
    private String mText;

    public CachedIconGenerator(Context context) {
        super(context);

        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = maxMemory / 8;
        mBitmapsCache = new LruCache<String, Bitmap>(cacheSize) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                // The cache size will be measured in kilobytes rather than
                // number of items.
                return bitmap.getByteCount() / 1024;
            }
        };
    }

    public Bitmap makeIcon(String text) {
        mText = text;
        return super.makeIcon(text);
    }

    @Override
    public Bitmap makeIcon() {
        if (TextUtils.isEmpty(mText)) {
            return super.makeIcon();
        } else {
            Bitmap bitmap = mBitmapsCache.get(mText);
            if (bitmap == null) {
                bitmap = super.makeIcon();
                mBitmapsCache.put(mText, bitmap);
            }
            return bitmap;
        }
    }
}
公共类CachedIconGenerator扩展IconGenerator{
专用最终LruCache mBitmapsCache;
私有字符串多行文字;
公共缓存生成程序(上下文){
超级(上下文);
final int maxMemory=(int)(Runtime.getRuntime().maxMemory()/1024);
//将可用内存的1/8用于此内存缓存。
最终int cacheSize=maxMemory/8;
mBitmapsCache=新的LruCache(cacheSize){
@凌驾
受保护的int-sizeOf(字符串键、位图){
//缓存大小将以KB为单位,而不是以字节为单位
//项目数量。
返回bitmap.getByteCount()/1024;
}
};
}
公共位图生成图标(字符串文本){
多行文字=文本;
返回super.makeIcon(文本);
}
@凌驾
公共位图生成图标(){
if(TextUtils.isEmpty(多行文字)){
返回super.makeIcon();
}否则{
位图Bitmap=mBitmapsCache.get(多行文字);
如果(位图==null){
位图=super.makeIcon();
mBitmapsCache.put(多行文字、位图);
}