2
I’m developing a graph generator to monitor the navigation of a robot. The coordinates the robot passes through are stored in a txt file, with each line having a latitude and a longitude, as described in that question. I’m using the @Victorstafusa example
But I’m having trouble accessing the class data Coordenada
.
To plot a line on my graph, I use the latitude and longitude of two coordinates. So I need each object to have the coordinates of a txt line. The code I use to plot a line is linha.drawLine(longitudeCoordenada1, latitudeCoordenada1, longitudeCoordenada2, latitudeCoordenada2)
. I then thought of instantiating objects as follows Coordenada c = new Coordenada()
, to use thus: linha.drawLine(c.getLongitude(), c.getLatitude(), c2.getLongitude(), c2.getLatitude())
. But I was unsuccessful.
I have little experience in object orientation, so you could tell me how to do so that each object has the coordinate of a txt line and how to access these coordinates?
To test I am using the following main class.
public class Main {
public static void main(String[] args) throws IOException {
double longitude1 = 0;
double latitude1 = 0;
double longitude2 = 0;
double latitude2 = 0;
Leitura l = new Leitura();
l.lerCoordenadas();
Coordenada c1 = new Coordenada(longitude1, latitude1);
Coordenada c2 = new Coordenada(longitude2, latitude2);
System.out.println(c1.getLongitude());
System.out.println(c1.getLatitude());
System.out.println(c2.getLongitude());
System.out.println(c2.getLatitude());
}
}
Look at that. When doing Coordinate c = new Coordinate() you are instantiating an object but without setting its values, so when you access it with c.getLongitude() the longitude value is null.
– Lucas Brogni
@Lucasbrogni In this case not even that. It is build error even because there is no constructor without parameters in this class.
– Victor Stafusa
"I use the latitude and longitude of two coordinates" - actually the opposite. The first coordinate on your list is
-54.123440,-21.123456
and the other coordinates are similar and very close. Interpreted as latitude-longitude, it is a point in the middle of the Atlantic Ocean not far from Antarctica, should not be a place of your interest. Interpreting as longitude-latitude, it is a place about 60km from Campo Grande - MS, which should be what interests you.– Victor Stafusa
Thanks for pointing out the error, I edited the question correcting it.
– BrunoPadilha