I have a text file containing NMEA frames. I retrieve the latitude and the longitude of $GPGGA and $GPRMC frames. For this part, it was okay.
Now, I'd like to convert the latitude and longitude into Decimal Degrees. The problem occur when I try to affect a values to Double[]coordinatestoconvert
. This one is always null.
It's like this error is really idiot, but I turn around all this morning for such a foolishness...
Can someone help me please ?
Here are the methods I am using :
public String readText(String filepath) throws Exception
{
String text="";
try
{
InputStream inputs=new FileInputStream(filepath);
InputStreamReader inputsreader=new InputStreamReader(inputs);
BufferedReader buffer=new BufferedReader(inputsreader);
String line;
while((line=buffer.readLine())!=null)
{
/* Server send to Client the full line. Then Client will select
* which data will be retrieve */
String[]splitedline=line.split(",");
Double[]decimalcoordinates=retrieveCoordinates(splitedline);
messagearea.append(decimalcoordinates[0].toString()+","+decimalcoordinates[1].toString());
tcpserver.sendMessage(decimalcoordinates[0].toString()+","+decimalcoordinates[1].toString());
}
buffer.close();
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
return text;
}
public Double[] retrieveCoordinates(String[] splitedline)
{
Double[]coordinates=null;
if((splitedline[0]=="$GPGGA") || (splitedline[0]=="$GPRMC"))
{
Double[]coordinatestoconvert=null;
// coordinatestoconvert is always null here
coordinatestoconvert[0]=Double.parseDouble(splitedline[3]);
coordinatestoconvert[1]=Double.parseDouble(splitedline[5]);
coordinates=convertNmeaToDecimal(coordinatestoconvert);
}
return coordinates;
}
public Double[] convertNmeaToDecimal(Double[] coordinatestoconvert)
{
Double[]coordinatesconverted=null;
for(int i=0;i<2;i++)
{
Double degrees=coordinatestoconvert[i]/100;
Double time=coordinatestoconvert[i]-degrees;
coordinatesconverted[i]=degrees+time/60;
}
return coordinatesconverted;
}