我有一个包含 NMEA 框架的文本文件。我检索 $GPGGA 和 $GPRMC 帧的纬度和经度。对于这部分,没关系。
现在,我想将纬度和经度转换为十进制度。当我尝试将值影响到 Double[]coordinatestoconvert
. 这个总是空的。
好像这个错误真的很白痴,但是我今天早上都在为这样的愚蠢而转身......
有人能帮助我吗 ?
以下是我正在使用的方法:
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;
}