0

速度に応じてポリラインに 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 );
        }
    }
    }
4

1 に答える 1

0

これが正しいかどうかはわかりませんが、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 );
    }
}
}
于 2014-01-11T03:05:37.677 に答える