NMEA フレームを含むテキスト ファイルがあります。$GPGGA および $GPRMC フレームの緯度と経度を取得します。この部分については、大丈夫でした。
ここで、緯度と経度を 10 進数に変換したいと思います。値を に変更しようとすると、問題が発生します Double[]coordinatestoconvert
。これは常に null です。
このエラーは本当にばかげているようですが、私は今朝ずっとその愚かさに振り返っています...
誰か助けてくれませんか?
私が使用している方法は次のとおりです。
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;
}