【问题标题】:How to change polyline color according to the speed如何根据速度改变折线颜色
【发布时间】:2014-01-11 02:57:14
【问题描述】:

我正在尝试制作一个应用程序,其中我根据速度为多段线设置了 3 种颜色,但它们没有显示多段线。我创建了一个函数并将其添加到多段线中,但没有显示线向上。 任何人都可以帮助我的代码如下::。 谢谢

    PolylineOptions rectOptions = new PolylineOptions();



@Override
public void onLocationChanged(Location location) {
 //   mMessageView.setText("Location = " + location);

    rectOptions.add(new LatLng(location.getLatitude(), location.getLongitude()));

     if (setIt == true){
         setcolortopoly();
          mMap.addPolyline(rectOptions);
     }
}

public void setcolortopoly(){
    if(mIsMetric){
        if(speed_poly<5.0){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.YELLOW );
        }
        else if(5.0<= speed_poly && speed_poly <10){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.GREEN );
        }
        else if(10.0<=speed_poly){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.RED );
        }

    }
    else{
        if(speed_poly<3.1){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.YELLOW );
        }
        else if(3.1<= speed_poly && speed_poly <6.21){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.GREEN );
        }
        else if(6.21<=speed_poly){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.RED );
        }
    }
    }

【问题讨论】:

    标签: java android google-maps google-maps-api-2 google-polyline


    【解决方案1】:

    我不确定这是否正确,但您似乎需要更改 if 循环的条件,请检查下面的代码是否可以进行一些更改::

             PolylineOptions rectOptions = new PolylineOptions();
    
    
    
      @Override
     public void onLocationChanged(Location location) {
     //   mMessageView.setText("Location = " + location);
    
    rectOptions.add(new LatLng(location.getLatitude(), location.getLongitude()));
    
     if (setIt == true){
         setcolortopoly();
          mMap.addPolyline(rectOptions);
     }
     }
    
     public void setcolortopoly(){
    if(mIsMetric){
        if(speed_poly<5.0){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.YELLOW );
        }
        else if(5.0>= speed_poly && speed_poly <10){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.GREEN );
        }
        else if(10.0>=speed_poly){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.RED );
        }
    
    }
    else{
        if(speed_poly<3.1){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.YELLOW );
        }
        else if(3.1>=speed_poly && speed_poly <6.21){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.GREEN );
        }
        else if(6.21>=speed_poly){
            rectOptions = new PolylineOptions().width(3).color(
                    Color.RED );
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      • 2019-12-10
      • 2019-03-20
      • 1970-01-01
      • 2021-09-19
      相关资源
      最近更新 更多