I’m trying to modify a .csv file to get a custom .kml file using javascript (I don’t almost nothing about programming) that displays the flight path of an aircraft with the altitude. I made the editting of the .csv manually (with Excel and others online tools) and I got this result:
Google Earth path view
The .csv look like this (but with much more lines):
latitude,longitude,altitude_feet,altitude_meters,speed_kmh,speed_kts,speed_mph,verticalSpeed_fpm,verticalSpeed_ms,heading,squawk,timestamp
-15.661926,-56.111912,0,0,5.6,3,3.5,0,0,326,0,1639064757
-15.661674,-56.112057,0,0,38.9,21,24.2,0,0,331,0,1639064777
-15.661263,-56.112274,0,0,68.5,37,42.6,0,0,334,0,1639064781
-15.661057,-56.112381,0,0,79.6,43,49.5,0,0,334,0,1639064782
-15.660778,-56.112537,0,0,92.6,50,57.5,0,0,334,0,1639064783
To make the .csv I just need the “latitude”, “longitude”, “altitude_meters” and “timestamp” columns.
For these columns to go in the .kml file they need to be edited and arranged in the following format:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document>
<name>AZU4534 10/12/2021 (SBCY-SBAT)</name>
<Placemark>
<name>SBCY Airport</name>
<Point>
<coordinates>-56.116719,-15.652931,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>SBAT Airport</name>
<Point>
<coordinates>-56.106206,-9.866092,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>AZU4534</name>
<description>SBCY-SBAT</description>
<gx:Track>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<when>2021-12-10T11:41:52Z</when>
<when>2021-12-10T11:41:57Z</when>
<when>2021-12-10T11:42:02Z</when>
<when>2021-12-10T11:42:05Z</when>
<when>2021-12-10T11:42:10Z</when>
<gx:coord>-56.117455 -15.651947 0</gx:coord>
<gx:coord>-56.117249 -15.652027 0</gx:coord>
<gx:coord>-56.117085 -15.652247 0</gx:coord>
<gx:coord>-56.116959 -15.652451 0</gx:coord>
<gx:coord>-56.116814 -15.652748 0</gx:coord>
</gx:Track>
</Placemark>
</Document>
</kml>
First part: the data and time
In the .kml file the “timestamp” column must be converted to a readable date (I think that with a math formula I can do that, but I don”t know to make this in javascript) in the following format: the date in yyyy-mm-dd, followed by a “T”, followed by the hour in hh-mm-ss, followed by a “Z”. All of this, in betweeen “<when>
” and “</when>
“.
Second part: coordinates and altitude
For the coordinates and altitude, it must follow this format: first comes the longitude, followed by a space, followed by the longitude, followed by another space, followed by the altitude. And again, all of this in between “<gx:coord>
” and “</gx:coord>
“.
So, any tips on how can I don that with javascript?
All I have now is a modification of an existing javascript: The “flightradar24-to-csv” by LuisSevillano (https://github.com/LuisSevillano/flightradar24-to-csv). And I would like to make a modification so that .kml file can be automatically generated.