'); $kml[] = ''; $kml[] = ''; $kml[] = 'Flight Path'; $kml[] = 'Site: ' . $scenario['latitude'] . ', ' . $scenario['longitude'] . ' at ' . $scenario['hour'] . ':' . $scenario['minute'] . ' on ' . $scenario['day'] . '/' . $scenario['month'] . '/' . $scenario['year'] . ']]>'; $kml[] = ''; $kml[] = ''; $kml[] = 'Flight path'; $kml[] = 'Ascent rate: ' . $scenario['ascent-rate'] . 'm/s, descent rate: ' . $scenario['descent-rate'] . 'm/s with burst at ' . $scenario['burst-altitude'] . 'm.' . ''; $kml[] = '#yellowPoly'; $kml[] = ''; $kml[] = '1'; $kml[] = '1'; $kml[] = 'absolute'; $kml[] = ''; // now print the lat/long/alt from the CSV // GE is retarded and wants its KML in the format LON,LAT,ALT - wtf $launch_lat; $launch_lon; $launch_time; $burst_lat; $burst_lon; $burst_time; $land_lat; $land_lon; $land_time; $max_alt = -10; $fh = fopen($flight_csv, "r") or die("Could not open file"); $i=0; while (($data = fgetcsv($fh)) !== FALSE) { $num = count($data); if ( $num < 4 ) die("Invalid XML"); $time = $data[0]; $lat = $data[1]; $lon = $data[2]; $alt = $data[3]; if ( $i == 0 ) { $launch_lat = $lat; $launch_lon = $lon; $launch_time = $time; } // see if the current point is above the last if ( $alt > $max_alt ) { $max_alt = $alt; $burst_lat = $lat; $burst_lon = $lon; $burst_time = $time; } // update this on every interation $land_lat = $lat; $land_lon = $lon; $land_time = $time; // add the formatted line to the KML array $kml[] = $lon . "," . $lat . "," . $alt; $i++; } $kml[] = ''; $kml[] = ''; // Make the launch marker $kml[] = ''; $kml[] = 'Balloon Launch'; $kml[] = 'Balloon launch at ' . $launch_lat . ', ' . $launch_lon . ' at ' . date("H:i d/m/Y", $launch_time) . '.'; $kml[] = '' . $launch_lon . ',' . $launch_lat . ',0' . ''; $kml[] = ''; // Make the burst marker $kml[] = ''; $kml[] = 'Balloon Burst'; $kml[] = 'Balloon burst at ' . $burst_lat . ', ' . $burst_lon . ' at ' . date("H:i d/m/Y", $burst_time) . ' with altitude ' . $max_alt . 'm.'; $kml[] = '' . $burst_lon . ',' . $burst_lat . ',' . $max_alt . ''; $kml[] = ''; // Make the land marker $kml[] = ''; $kml[] = 'Predicted Balloon Landing'; $kml[] = 'Balloon landing at ' . $land_lat . ', ' . $land_lon . ' at ' . date("H:i d/m/Y", $land_time) . '.'; $kml[] = '' . $land_lon . ',' . $land_lat . ',0' . ''; $kml[] = ''; $kml[] = ''; $kmlOut = join("\n", $kml); header("Content-type: application/vnd.google-earth.kml+xml"); header("Content-Disposition: attachment; filename=".$uuid.".kml"); echo $kmlOut; ?>