0
我有這個數據庫: 谷歌地圖繪製v2的折線取決於速度
和我試圖做一個簡單的折線圖紙是取決於速度這樣:
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));
}
代碼中的任何建議? – David
你是對的我的方法正在更新好的一個 – David