在Google Maps v2 for Android上重绘位图

jet*_*hro 9 android google-maps-android-api-2

在这种情况下,我想在Google地图上使用绘制位图gms v2,每个用户位置更新都会强制执行位图更新.目前我使用以下代码段:

public void init(){
    result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    canvas = new Canvas(result);
}

public void update(){
    // draw on canvas ...
    draw(result);
}

public void draw(Bitmap modifiedBmp) {
    if (overlay != null) {
        overlay.remove();
    }

    BitmapDescriptor descriptor = BitmapDescriptorFactory.fromBitmap(modifiedBmp);
    overlay = map.addGroundOverlay(new GroundOverlayOptions().image(descriptor).positionFromBounds(bounds).zIndex(100));
} 
Run Code Online (Sandbox Code Playgroud)

update()每秒调用该方法.我发现这种方法非常低效,我正在寻找更好的解决方案(即每次更新后不需要添加/删除叠加).使用addPolygon(...)addPolyline(...)不是选项在地图上绘制图元,因为我需要标准API中不存在的绘图功能.

War*_*zit 7

一个优化可能是检查新位置是否与旧位置相同,如果是这种情况则不重绘.另外我不认为每次都需要创建描述符.

这里描述了移动标记的另一种方法.这是官方样本中的一个.