android - google maps v2 draw polyline depends on speed -


i have database: enter image description here

and i've tried make simple polyline drawing depends on speed way:

cursor curtab = mydatabase.rawquery("select *  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); 

but every line same color. please me did wrong!

update: working code(at last point doesn't work not big problem)

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));          } 

i'm not familiar maps-android-api, looks if add new polyline each db-entry have same path polyline added before plus new latlng current entry.

the result see polyline created last entry cover other polylines.

i guess need set new polylineoptions-object on each iteration , add points latlngs of recent entry , of current entry desired result.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -