【问题标题】:Add polyline to google maps with different colors android将折线添加到具有不同颜色android的谷歌地图
【发布时间】:2020-10-24 10:31:25
【问题描述】:

我正在尝试从 Firebase 获取坐标,以便在 Google 地图上为每个用户创建不同颜色的折线。问题是当我获取这些数据并将其插入谷歌地图时,它以相同的颜色显示。

List<Integer> colors = new ArrayList<>();
colors.add(-9784993);
colors.add(-6501807);

for (int a = 0; a <= userList.size()-1; i++) {

     for (DataSnapshot objSnapshot : dataSnapshot.getChildren()) {

          dataClass d = objSnapshot.getValue(dataClass.class);

          LatLng start = new LatLng(d.getLat(), d.getLongi());

          elasticList.add(start);

          polylineOptionsTest[a] = new PolylineOptions()
               .addAll(elasticList)
               .color(colors.get(a)) //Get color from list called "colors"
               .clickable(true);
          polyline2 = mMap.addPolyline(polylineOptionsTest[a]);

        }
}

【问题讨论】:

    标签: android google-maps polyline


    【解决方案1】:

    这可能是因为userList.size() 等于1 并且colors.get(a) 总是返回colors[0] (-9784993) 颜色。换句话说,您为单个用户添加折线。

    更新:错误出现在 for 循环中 - 你应该使用:

    for (int a = 0; a <= userList.size()-1; a++) {
    

    而不是

    for (int a = 0; a <= userList.size()-1; i++) {
    

    你增加了i变量,而不是a

    【讨论】:

    • userList.size() 大于 1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 2020-08-06
    • 2011-09-09
    • 2013-03-03
    • 1970-01-01
    • 2014-07-07
    • 2013-07-25
    相关资源
    最近更新 更多