plotting gps please help
in
Programming Questions
•
1 year ago
hi all
im trying to plot latitude ,longitude and display the the completed track but can only display the current position as the file is read . I believe i need to create an array list to store the positions before they can be permanently displayed
can somone offer some help with this.
many thanks
this is the code im running with a sample of the gps code at the bottom.
BufferedReader reader;
String line;
//-----------------------
float latitude =0.0;
String northSouth;
float longitude = 0.0;
String eastWest;
float heading = 0.0;
float speed =0.0;
int hrs,mins,secs;
int thisDay, thisMonth,thisYear;
//-----------------------------------
float x;
float y;
PImage raster;
void setup() {
size(1700, 700);
//-----------------
PFont myFont =createFont(PFont.list()[2],24);
textFont(myFont);
//-------------
ellipseMode(CENTER);
smooth();
frameRate(10);
// Open the file from the createWriter() example
reader = createReader("gprmc.txt");
}
void draw() {
background (0);
fill (255);
text(thisMonth+"/"+thisDay+"/"+thisYear,50,30);
text(hrs+":"+mins+":"+secs +" ",50,50);
text("Lng" +" " +eastWest, 50,70);
text("Lat " +" "+northSouth , 50,90);
text("heading "+ heading + "degrees",50,110);
// text(hrs+":"+mins+":"+secs +"GMT ",50,130);
//text("Lat " +" "+northSouth , 50,130);
// text("heading "+ heading + "degrees",50,150);
text("Speed M/Sec "+ speed ,50,170);
// drawArrow(heading);
try {
line = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
line = null;
}
if (line == null) {
println();
// Stop reading because of an error or file is empty
//noLoop();
} else {
String[] pieces = split(line, ",");
println();
//-----------------------------------
//if (pieces[0].equals("$GPRMC")){
//----------------------------
int time = int(pieces[1]);
//first two digits of time are the hours
//if (pieces[0].equals("$GPRMC")){
// getRMC (pieces);
if (pieces[0].equals("$GPRMC")){
float latitude = float(pieces[3])/100.0;
float longitude= float(pieces[5])/100.0;
heading = float (pieces[7]);
northSouth = (pieces[5]);
eastWest = (pieces [3]);
speed = float(pieces [7]);
int date = int (pieces[9]);
thisYear =date0+2000;
//second two digits are month
thisMonth =(date000)/100;
//first two digits of date are day
thisDay = date/10000 ;
if (pieces.length == 13) {float mapX = float(pieces[3]);
float mapY = float(pieces[5]);
println(mapX + " " + mapY);
//println();
float w_start = 00048.0990; // Longtitude start (largest longitude value)
float w_end = 00048.06929; // Longtitude end (smallest longitude value)
float h_start = 5120.1023; // Latitude start (largest latitude value)
float h_end = 5120.060012; // Latitude end (smallest latitude value)
int mapX1 = 0;
int mapX2 = width;
int mapY1 = 0;
int mapY2 = height;
x = int(((180+mapY)/360)*width);
y = int(height - ((90+mapX)/180)*height);
x = map(mapY, w_start, w_end, mapX1, mapX2);
y = map(mapX, h_end, h_start, mapY1, mapY2);
ellipse(x, y, 10, 10);
hrs= time/1000;
//second two digits=minutes
mins = (time000)/100;
//last two digits =seconds
secs = (time0);
}}
drawArrow(heading);
}
}
//--------------
void drawArrow (float angle){
translate(width/2,height/2);
fill(80,200,230);
ellipse(0,0,50,50);
fill (0);
rotate(radians(angle));
//draw the arrow .centre of arrow is at 0.0
triangle (-10,0,0,-20,10,0);
rect(-2,0,4,20);
//}
//background (0);
}
sample gps - gprmc.text
$GPRMC,125924.00,A,5120.07122,N,00048.08916,E,0.081,,221211,,,A*79
$GPRMC,125925.00,A,5120.07131,N,00048.08929,E,0.096,,221211,,,A*70
$GPRMC,125926.00,A,5120.07125,N,00048.08864,E,0.117,,221211,,,A*76
$GPRMC,125927.00,A,5120.07127,N,00048.08883,E,0.279,,221211,,,A*77
$GPRMC,125928.00,A,5120.07137,N,00048.08842,E,0.490,,221211,,,A*75
$GPRMC,125930.00,A,5120.07136,N,00048.08822,E,0.782,,221211,,,A*7B
$GPRMC,125932.00,A,5120.07125,N,00048.08877,E,0.803,,221211,,,A*7D
$GPRMC,125934.00,A,5120.07026,N,00048.08660,E,0.408,,221211,,,A*76
$GPRMC,125936.00,A,5120.06974,N,00048.08493,E,0.024,,221211,,,A*7F
$GPRMC,125937.00,A,5120.06959,N,00048.08464,E,0.072,,221211,,,A*7A
$GPRMC,125938.00,A,5120.06950,N,00048.08428,E,0.067,,221211,,,A*70
$GPRMC,125941.00,A,5120.06957,N,00048.08386,E,0.135,,221211,,,A*7C
$GPRMC,125942.00,A,5120.06952,N,00048.08369,E,0.123,,221211,,,A*7C
$GPRMC,125943.00,A,5120.06950,N,00048.08361,E,0.116,,221211,,,A*71
$GPRMC,125944.00,A,5120.06951,N,00048.08362,E,0.088,,221211,,,A*72
$GPRMC,125945.00,A,5120.06955,N,00048.08363,E,0.107,,221211,,,A*70
$GPRMC,125947.00,A,5120.06966,N,00048.08353,E,0.112,,221211,,,A*75
$GPRMC,125948.00,A,5120.06975,N,00048.08346,E,0.088,,221211,,,A*7E
$GPRMC,125950.00,A,5120.06983,N,00048.08331,E,0.085,,221211,,,A*73
$GPRMC,125952.00,A,5120.06994,N,00048.08326,E,0.271,,221211,,,A*78
$GPRMC,125953.00,A,5120.06998,N,00048.08328,E,0.121,,221211,,,A*7D
$GPRMC,125954.00,A,5120.06999,N,00048.08326,E,0.107,,221211,,,A*71
$GPRMC,125955.00,A,5120.07000,N,00048.08326,E,0.079,,221211,,,A*70
$GPRMC,125958.00,A,5120.07002,N,00048.08327,E,0.083,,221211,,,A*7B
$GPRMC,130002.00,A,5120.07017,N,00048.08332,E,0.086,,221211,,,A*7C
$GPRMC,130003.00,A,5120.07023,N,00048.08332,E,0.097,,221211,,,A*7A
$GPRMC,130005.00,A,5120.07020,N,00048.08333,E,0.086,,221211,,,A*7E
$GPRMC,130008.00,A,5120.07028,N,00048.08343,E,0.102,,221211,,,A*71
$GPRMC,130010.00,A,5120.07033,N,00048.08345,E,0.118,,221211,,,A*7F
$GPRMC,130012.00,A,5120.07039,N,00048.08338,E,0.082,,221211,,,A*7F
$GPRMC,130014.00,A,5120.07039,N,00048.08333,E,0.076,,221211,,,A*79
$GPRMC,130015.00,A,5120.07042,N,00048.08333,E,0.108,,221211,,,A*7C
$GPRMC,130016.00,A,5120.07043,N,00048.08333,E,0.100,,221211,,,A*76
$GPRMC,130018.00,A,5120.07049,N,00048.08336,E,0.088,,221211,,,A*76
$GPRMC,130019.00,A,5120.07051,N,00048.08340,E,0.129,,221211,,,A*75
$GPRMC,130021.00,A,5120.07054,N,00048.08349,E,0.060,,221211,,,A*7E
$GPRMC,130024.00,A,5120.07050,N,00048.08357,E,0.125,,221211,,,A*70
$GPRMC,130025.00,A,5120.07046,N,00048.08355,E,0.074,,221211,,,A*71
$GPRMC,130028.00,A,5120.07046,N,00048.08350,E,0.177,,221211,,,A*7B
$GPRMC,130029.00,A,5120.07049,N,00048.08350,E,0.133,,221211,,,A*75
$GPRMC,130031.00,A,5120.07048,N,00048.08351,E,0.123,,221211,,,A*7D
$GPRMC,130033.00,A,5120.07050,N,00048.08356,E,0.162,,221211,,,A*74
$GPRMC,130034.00,A,5120.07051,N,00048.08357,E,0.108,,221211,,,A*7F
$GPRMC,130035.00,A,5120.07050,N,00048.08359,E,0.124,,221211,,,A*7F
$GPRMC,130038.00,A,5120.07042,N,00048.08358,E,0.115,,221211,,,A*72
$GPRMC,130040.00,A,5120.07040,N,00048.08358,E,0.177,,221211,,,A*7B
$GPRMC,130043.00,A,5120.07032,N,00048.08355,E,0.117,,221211,,,A*76
$GPRMC,130044.00,A,5120.07027,N,00048.08355,E,0.155,,221211,,,A*73
$GPRMC,130047.00,A,5120.07021,N,00048.08354,E,0.145,,221211,,,A*76
$GPRMC,130049.00,A,5120.07013,N,00048.08355,E,0.276,,221211,,,A*7B
1