【问题标题】:how to put progress bar around map marker(car)如何在地图标记(汽车)周围放置进度条
【发布时间】:2020-01-11 08:33:47
【问题描述】:

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

【问题讨论】:

  • 您可能必须拥有多个标记图像并根据进度值更新标记图像。
  • 你认为进度是多个标记出现和消失?
  • 您可以自定义标记的图像。您也可以随时更改标记的图像。根据进度更改它,例如 10 个不同的标记图像中的 1 个(0、10%、20%...)。
  • 你能给我看一个演示或链接吗?

标签: java android xml google-maps kotlin


【解决方案1】:

在这个短片中,进度标记(标记周围的一系列 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;

视频

【讨论】:

  • 谢谢安迪,我对这些步骤很了解,我做到了,只是我需要切换管理器,你能详细发布这部分代码吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-07
  • 1970-01-01
  • 2021-04-10
  • 1970-01-01
  • 1970-01-01
  • 2018-02-11
相关资源
最近更新 更多