如何在地图标记周围放置进度条(汽车)

时间:2020-01-11 08:33:47

标签: java android xml google-maps kotlin

enter image description here

我希望像这样的图像一样围绕Google地图标记制作进度条,或者如何在地图上显示具有特定位置的进度条,就像我告诉纬度和经度并显示该位置一样

1 个答案:

答案 0 :(得分:0)

在此简短剪辑中,进度标记(围绕标记的一系列8个圆)以一个填充的圆圈前进,表示进度-基于任何进度计算需要(在这种情况下,需要5个位置更新,但很可能会完成距离)。

标记图标是完整的东西(汽车+标记针+进度圈),并且在9个文件中重复了该图标,更改了进度圈。

如果感兴趣,我可以发布详细信息,但摘要为:

  • 创建与进度状态一样多的标记图像(本示例中为9)
  • 通过更改与进度相对应的标记图标(在此示例中以1/8为增量)来定期更新进度
  • 通过处理程序延迟来完成闪烁,并且基本上在icon0(未填充圆圈)和当前图标(基于进度计算)之间切换。
  • 在此示例中,只需使用.setPosition(),标记就会随位置一起移动。

以下是提供的示例的处理程序实现:

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
 boolean onOff = false;
 @Override
 public void run() {
     // imageId is set in the onLocationChanged based on 'progress'
     // determination - 0/8 complete; 1/8 complete...
     int currentImageId = imageId;

     // icons is an array list populated at initialization with 
     // BitmapDescriptors from resources - one for each progress
     // fraction (0 - 8).
     BitmapDescriptor currentIcon = icons.get(currentImageId);

     // Flashing results from using the "0-progress" indicator icon
     // which is at index 0.
     BitmapDescriptor offIcon = icons.get(0);

     if (onOff) {
         marker1.setIcon(offIcon);
     } else {
         marker1.setIcon(currentIcon);
     }
     onOff = !onOff;

     // restart handler timer.
     handler.postDelayed(this, 500);
 }
}, 100);

图标列表的初始化如下:

// repeat for all progress images
final BitmapDescriptor icon0 = BitmapDescriptorFactory.fromResource(R.drawable.car0);

// and add to list
final ArrayList<BitmapDescriptor> icons = new ArrayList<>();
// repeat for all progress images
icons.add(icon0);

定制来自“进度确定”-如果沿着路线行驶,则在onLocationChanged中计算路径完成率,并将其应用于最大图像数量,以产生上述imageId。如:

int imageId = pathCompleteRatio * maxImages;

视频 enter image description here