Android 谷歌地图v2绘制多段线取决于速度
我有这个数据库: 我试着画一个简单的多段线,这取决于速度:Android 谷歌地图v2绘制多段线取决于速度,android,google-maps,Android,Google Maps,我有这个数据库: 我试着画一个简单的多段线,这取决于速度: 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_s
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);
Cursor curTAB=myDataBase.rawQuery(“从GPS_值中选择*”,null);
整数计数=0;
while(curTAB.moveToNext()){
字符串s_纬度=curTAB.getString(1);
字符串s_经度=curTAB.getString(2);
字符串s_速度=curTAB.getString(5);
计数++;
双纬度=double.parseDouble(s_纬度);
双经度=double.parseDouble(s_经度);
intspeed=Integer.parseInt(curTAB.getString(5.toString());
if(speed我不熟悉maps android API,但它看起来好像为每个db条目添加了一条新的多段线,该多段线的路径与在之前添加的多段线加上当前条目的新LatLng的路径相同
结果是,您将只看到为最后一个条目创建的多段线,该条目将覆盖所有其他多段线
我想您需要在每次迭代中设置一个新的PolylineOptions对象,并将最近条目和当前条目的LatLngs添加为点,以获得所需的结果
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));
}