私はこのデータベースを持っています:
そして、私はこのように速度に依存する単純なポリライン描画を作成しようとしました:
Cursor curTAB = myDataBase.rawQuery("SELECT * FROM GPS_Values;", null);
Integer count = 0;
while (curTAB.moveToNext()) {
String s_latitude = curTAB.getString(1);
String s_longitude = curTAB.getString(2);
String s_speed = curTAB.getString(5);
count++;
double latitude = Double.parseDouble(s_latitude);
double longitude = Double.parseDouble(s_longitude);
int speed = Integer.parseInt(curTAB.getString(5).toString());
if (speed <= 50) {
Log.i("Coordinates",
s_latitude.toString() + " --- " + s_longitude.toString() + " --- " +s_speed.toString());
line.add(new LatLng(latitude, longitude)).color(Color.GREEN);
line.color(Color.GREEN);
map.addPolyline(line);
} else {
Log.e("Coordinates",
s_latitude.toString() + " --- " + s_longitude.toString() + " --- " +s_speed.toString());
line.add(new LatLng(latitude, longitude)).color(Color.BLUE);
line.color(Color.BLUE);
map.addPolyline(line);
}
Log.i("Coordinates",
s_latitude.toString() + " --- " + s_longitude.toString() + " --- " +s_speed.toString());
}
curTAB.close();
myDataBase.close();
double latitude = Double.parseDouble(first_lat);
double longitude = Double.parseDouble(first_long);map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,
longitude), 15));
map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
しかし、すべての行は同じ色です。何が間違っていたのか助けてください!
更新: 動作するコード (最後の時点では動作しませんが、大きな問題ではありません)
Integer count = 0;
while (curTAB.moveToNext()) {
String s_latitude = curTAB.getString(1);
String s_longitude = curTAB.getString(2);
String s_speed = curTAB.getString(5);
double latitude = Double.parseDouble(s_latitude);
double longitude = Double.parseDouble(s_longitude);
int speed = Integer.parseInt(curTAB.getString(5).toString());
int position = curTAB.getPosition();
count++;
System.out.println("Curr " + latitude + " --- " + longitude
+ " --- " + speed);
if (curTAB.moveToNext()) {
String next_speed = curTAB.getString(5);
String ss_latitude = curTAB.getString(1);
String ss_longitude = curTAB.getString(2);
System.out.println("Next " + ss_latitude + " --- "
+ ss_longitude + " --- " + next_speed);
curTAB.moveToPosition(position);
double n_latitude = Double.parseDouble(ss_latitude);
double n_longitude = Double.parseDouble(ss_longitude);
if (speed > 60) {
map.addPolyline(new PolylineOptions()
.add(new LatLng(latitude, longitude),
new LatLng(n_latitude, n_longitude))
.width(10).color(Color.RED));
} else if ((speed < 56) && (speed > 31)) {
map.addPolyline(new PolylineOptions()
.add(new LatLng(latitude, longitude),
new LatLng(n_latitude, n_longitude))
.width(10).color(Color.GREEN));
} else if (speed < 31) {
map.addPolyline(new PolylineOptions()
.add(new LatLng(latitude, longitude),
new LatLng(n_latitude, n_longitude))
.width(10).color(Color.rgb(255, 127, 80)));
}
}else{
System.out.println("VÉGE");
}
line.add(new LatLng(latitude, longitude));
}