Array assignment issue ..
in
Contributed Library Questions
•
1 year ago
Hy guys ! I'm writing a program to read some position stored in a db and show them on a map using unfolding library. During the sql query I wanna parse the gps data into a float array (lat[], lng[]). I get stucked if i try to put them in the array but it works fine if I store in a float. Sorry if the code is such a shame but I'm a newbie ;-)
- import guicomponents.*;
- import de.bezier.data.sql.*;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- import de.fhpotsdam.unfolding.*;
- import de.fhpotsdam.unfolding.geo.*;
- import de.fhpotsdam.unfolding.utils.*;
- Date start,end;
- SQLite db;
- de.fhpotsdam.unfolding.Map map;
- float m = millis();
- GTextField txf_1, txf_2;
- GTextField s_day, s_month, s_year, e_day, e_month, e_year, consolefield;
- GLabel lblgiorno,lblmese,lblanno,lblinizio,lblfine;
- GButton ok;
- int x,y;
- String a,sd,sm,sy,ed,em,ey,startdate,enddate;
- void setup() {
- db = new SQLite( this, "prova.db" ); // open database file
- int xmain=1280,ymain=700;
- x=80;
- y=ymain-46;
- //MAPPA
- map = new de.fhpotsdam.unfolding.Map(this, "map",10,10,xmain-230,y-20);
- map.zoomAndPanTo(new Location(41.75192, 12.85258), 15);
- MapUtils.createDefaultEventDispatcher(this, map);
- size(xmain, ymain, GLConstants.GLGRAPHICS);
- //posizione form
- //txf_1 = new GTextField(this, "Hello ", 10, 10, 160, 20, false);
- //txf_1.setBorder(0);
- //txf_1.addEventHandler(this, "handleMyTextFieldEvents");
- //txf_2 = new GTextField(this, "Goodbye ", 10, 40, 160, 20, false);
- consolefield = new GTextField(this, "", xmain-210, 10, 200, ymain-20, true);
- s_day = new GTextField(this, "dd", x, y, 28, 16);
- s_day.addEventHandler(this, "handle_s_dayEvents");
- s_month = new GTextField(this, "mm", x+40, y, 30, 16);
- s_month.addEventHandler(this, "handle_s_monthEvents");
- s_year = new GTextField(this, "yyyy", x+80, y, 50, 16);
- s_year.addEventHandler(this, "handle_s_yearEvents");
- e_day = new GTextField(this, "dd", x, y+20, 28, 16);
- e_day.addEventHandler(this, "handle_e_dayEvents");
- e_month = new GTextField(this, "mm", x+40, y+20, 30, 16);
- e_month.addEventHandler(this, "handle_e_monthEvents");
- e_year = new GTextField(this, "yyyy", x+80, y+20, 50, 16);
- e_year.addEventHandler(this, "handle_e_yearEvents");
- //lblgiorno= new GLabel(this, "giorno", 10,10,40,16);
- //lblmese= new GLabel(this, "mese", 50,10,40,16);
- //lblanno= new GLabel(this, "anno", 90,10,40,16);
- lblinizio= new GLabel(this, "Inizio", x-50,y,40,16);
- lblfine= new GLabel(this, "Fine", x-50,y+20,40,16);
- ok = new GButton(this, "Ok", x+160, y+10, 30, 20);
- ok.tag = "Button OK";
- }
- public void handleMyTextFieldEvents(GTextField t) {
- println("textField");
- if (t.eventType == GTextField.ENTERED) {
- println(" Event type ENTERED");
- }
- else if (t.eventType == GTextField.CHANGED) {
- println(" Event type CHANGED");
- }
- else if (t.eventType == GTextField.SET) {
- println(" Event type SET");
- }
- }
- void handleTextFieldEvents(GTextField t) {
- println("textField");
- if (t.eventType == GTextField.ENTERED) {
- println(" Event type ENTERED");
- }
- else if (t.eventType == GTextField.CHANGED) {
- println(" Event type CHANGED");
- a=t.getText() ;
- }
- }
- void handleButtonEvents(GButton button) {
- if(button == ok){
- startdate = (sd+"/"+sm+"/"+sy);
- enddate = (ed+"/"+em+"/"+ey);
- println(startdate);
- println(enddate);
- estraidb();
- }
- }
- void draw() {
- background(255);
- map.draw();
- //dotrender();
- if (millis()>m+20000){
- println("passati 20 secondi");
- m=millis();
- checkdb();
- }
- }
- void dotrender() {
- for (int p=0; p<i; p++){
- Location loc = new Location((coord[p][0]),(coord[p][1]));
- float xyonmap[] = map.getScreenPositionFromLocation(loc);
- fill(200, 0, 0, 100);
- float s = map.getZoom();
- ellipse(xyonmap[0], xyonmap[1], s, s);
- }
- }
- import de.bezier.data.sql.*;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- int i=0;
- long laststamp=0;
- long numerosonda=+3912345;
- float coord[][];
- float xyonmap[];
- String data;
- String[] dataparsed;
- float[] lat;
- float[] lng;
- public void estraidb()
- {
- DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
- try {
- start = df.parse(sd+"/"+sm+"/"+sy);
- end = df.parse(ed+"/"+em+"/"+ey);
- } catch(ParseException e) {
- println(e);}
- long startstamp = start.getTime()/1000;
- long endstamp = end.getTime()/1000;
- if ( db.connect() )
- {
- // read all in table "table_one"
- db.query( "SELECT * FROM message where date BETWEEN '"+startstamp+"' AND'"+endstamp+"' AND address='+3912345'" );
- while (db.next())
- {
- estraicoordinate();
- println(data);
- println(dataparsed[0]);
- println(dataparsed[1]);
- //println(lat[0]);
- }
- }
- }
- void checkdb(){
- if (db.connect()){
- db.query( "SELECT * from message where address='"+numerosonda+"' AND date >'"+laststamp+"'" );
- if (db.next()) {
- println("Nuovi dati disponibili") ;
- //estraidb(); //PASSARE IL PARAMETRO LASTSTAMP AL METODO !!
- }
- else println("Database aggiornato");
- }
- }
- void estraicoordinate() {
- data=db.getString("text");
- dataparsed = splitTokens(data, ",");
- println(i);
- lat[i]=float(dataparsed[0]);
- lng[i]=float(dataparsed[1]);
- //coord[0][i]=prova;
- //coord[1][i]=float(dataparsed[1]);
- laststamp=db.getLong("date");
- i++;
- }
1