Skip to content

Instantly share code, notes, and snippets.

@pl4nty
Created December 5, 2023 03:41
Show Gist options
  • Save pl4nty/eacfcf1bd7f1df5b79fa7e637ec81e08 to your computer and use it in GitHub Desktop.
Save pl4nty/eacfcf1bd7f1df5b79fa7e637ec81e08 to your computer and use it in GitHub Desktop.
Qantas flight tracker
// Got bored on a flight and their tracker was broken, so I spent half an hour writing a tracker
// Relies on Viasat in-flight entertainment system, tested on a Qantas Boeing 737
// Uses geocoding for origin/destination coordinates, but untested and commented cause I hit a ratelimit
const POLL_INTERVAL_MS = 3000;
async function initMap() {
const { Map, InfoWindow } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
const map = new Map(document.getElementById("map"), {
zoom: 3,
mapTypeId: google.maps.MapTypeId.TERRAIN,
mapId: 'DEMO_MAP_ID'
});
//const geocoder = new Geocoder({key: "DEMO_MAP_ID"});
const markers = [0,1,2].forEach(() => new AdvancedMarkerElement({ map }));
const [plane, origin, dest] = markers;
const img = document.createElement("img");
img.src = "https://static.vecteezy.com/system/resources/previews/022/093/350/original/top-view-of-plane-silhouette-icon-free-png.png";
img.height = 20;
img.width = 20;
plane.content = img;
const infoWindow = new InfoWindow();
markers.forEach(marker => {
marker.addListener("click", ({ domEvent, latLng }) => {
const { target } = domEvent;
infoWindow.close();
infoWindow.setContent(marker.title);
infoWindow.open(marker.map, marker);
})
})
const pollData = async () => {
let res = await fetch("https://qantas.viasat.com/device")
const data = await res.json()
const position = { lat: data.latitude, lng: data.longitude, altitude: data.altitude }
map.setCenter(position);
plane.position = position;
plane.title = `${data.flightNumber} on ${data.tailId}, landing in ${data.flightMinutesRemaining} mins`
img.style.transform = `rotate(${data.heading}deg)`
//res = await geocoder.geocode({ "address": data.flightOrigin })
origin.title = data.flightOrigin
//origin.position = res[0].position
//res = await geocoder.geocode({ "address": data.flightDestination })
dest.title = `${data.flightDestination}. ${data.destinationConditions} and ${data.destinationTemperature}°F`
//dest.position = res[0].position
}
await pollData();
setInterval(pollData, POLL_INTERVAL_MS)
}
initMap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment