0
I’m trying to make a code that reads latitudes and longitudes that are in a txt file. I mean, put what’s in the file in a vector and make a loop for to call everyone inside the Polyline.
try {
File file = getFileStreamPath("circular_1.txt");//se eu puder usar uma variavel aki seria melhor pois o nome do arquivo vai ir sempre mudando
int x = 0;
FileReader reader = new FileReader(file);
BufferedReader leitor = new BufferedReader(new InputStreamReader(getAssets().open("ufpa_circular_1.txt")));
Double[] coord = new Double[192];
String linha;
while ((linha = leitor.readLine()) != null) {
coord[x++] =Double.parseDouble(linha);
}
for (x = 0; x < 192; x = x + 2) {
Polyline line = map.addPolyline(new PolylineOptions()
.add(new LatLng(coord[x], coord[x + 1]), new LatLng(coord[x + 2], coord[x + 3]))
.width(5)
.color(Color.BLUE));
}
leitor.close();
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
the problem is that Polyline never appears when I put this code and I am not finding the error in it. I tried to put the file on raw and use R.raw and Assets and use getAssets(), neither of the two opened Polyline either the lines are without boundaries, that is, I only gave enter even to go to another line, but before had made a text delimiting with ; and using stringtokenizer and also did not appear the polylines
Your problem is reading the file, transforming into Polyline or displaying the data? Not enetendi what is the problem. Data is loaded correctly into Polyline?
– Thiago Luiz Domacoski
Are you sure you’re reading from the file right? The fact of using two files (in the variables "Reader" and "reader"), but only read from one of them seems to me very suspicious.
– Victor Stafusa
The title of the question does not match the description. The title says that the problem lies in loading data from a txt into an array. The description says you are having trouble with polylines. You were able or not to load the data into the vector?
– Fagner Fonseca