Traffic Alerts (Web Client)


The Traffic Alert API allows developers to provide their pilots with alerts about nearby traffic - including commercial airplanes, general aviation airplanes, helicopters, and some unmanned aircraft. The traffic feed is a combination of several highly reliable sources used by the airline industry. The Traffic Alert API automatically filters to alert the operator of only traffic that is low-altitude and near the current flight path.



The Traffic Alert API requires a few other AirMap services in order to function. If you are not familiar with these tools, check out the respective guides before proceeding:

  1. Authentication: See the Authentication Module for an easy JS implementation or SSO Authentication for an API login.

  2. Flight API: You must create a flight prior to using the Traffic Alert API (since the Traffic Alert API needs to know where to filter traffic for your flight). See Creating and Viewing Flights

  3. MQTT Client Library (External): The Traffic Alert API passes traffic over MQTT, a lightweight, highly efficient messaging protocol. MQTT has been implemented in many different languages, including C/C++, Java, JavaScript, Python, Lua, and others. The examples in this guide use JavaScript and the popular Paho JavaScript Client


Create a new HTML page and include an MQTT Client Library--Paho in this example.

<!DOCTYPE html>
<html lang="en">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <script src=""></script>
    <script src="" type="text/javascript"></script>






Next, you will need to add in authentication and create a flight before listening for traffic. Choose an arbitrary flight location near an airport for this for this example:


  // Full authentication not shown - see Auth Module
  // ...
  // ...
  var token = auth.getUserToken()

  // Create simple flight

  var flight_id = ""
  var lat = 34.0248
  var lon = -118.44267
  var buffer = 1000

  var data = {
    latitude: lat,
    longitude: lon,
    buffer: buffer

    url: "",
    headers: {
      "X-API-KEY": "<YOUR_API_KEY>",
      "Authorization": "Bearer " + auth.getUserToken(),
      "Content-Type": "application/json; charset=utf-8"
    type: "post",
    data: JSON.stringify(data),
    dataType: "json",
    success: function(res) {

      flight_id =

      console.log("Flight created: " + flight_id)


    error: function(err) {
      alert( + ":" + err.message)

You have now successfully created a flight and can start listening for traffic--you just need to implement the listenTraffic() function. Before doing that, however, here are some key parameters for setting up an MQTT connection:



Web browsers donโ€™t support native MQTT packets and instead use a web socket implementation of the MQTT protocol at port 8884. If you are not using a web browser, please use port 8883.
clientIdMust be unique per client
userNameEx: "flight|abc123..."
Alert Topicuav/traffic/alert/<flight id>
Situational Awareness
uav/traffic/sa/<flight id>Situational Awareness traffic topic does not include messages dispatched via the alert topic.

Note that you can subscribe to two different topics. The Situational Awareness Topic provides all traffic that is near a drone flight, while the Alert Topic provides only traffic that is heading directly toward the drone flight. You may subscribe to only one, or both simultaneously.

Also note that for this web client example, the WebSockets port used to connect to the MQTT broker is 8884 (since native MQTT is not supported in the browser). However, when connecting a client using native MQTT, the correct port number is 8883.

Here is the implementation of listenTraffic that you can place at the bottom of the <script>:

function listenTraffic() {

  // SOME MQTT CLIENTS require a "/mqtt" at the end of the URL
  var client = new Paho.MQTT.Client('', 8884, "c-mqtt-cli")

  client.onMessageArrived = onMessageArrived

  function onMessageArrived(message) {
    console.log("onMessageArrived:" + message.payloadString);

    onSuccess: onConnect,
    userName: flight_id,
    password: auth.getUserToken(),
    useSSL: true

  function onConnect() {


    var topic_alert = 'uav/traffic/alert/' + flight_id

    var topic_sa = 'uav/traffic/sa/' + flight_id




Now, whenever traffic is received, it will be printed out in the console:


The payloadString in the MQTT message contains a JSON string that is an array of traffic objects (i.e. "traffic": [t1,t2,...]). Here are the parameters for each traffic object:

idunique id of traffic
directionDirection of aircraft relative to UAS flight (client)
altitudeAltitude of aircraft in feet
latitudeLatitude in decimal degrees
longitudeLongitude in decimal degrees
recorded_timeUTC time aircraft was recorded
ground_speed_ktsGround speed in knots
true_headingTrue heading of aircraft in degrees
properties.aircraft_idAircraft tail number
timestampUTC time aircraft alert sent out

Updated 3 years ago

Traffic Alerts (Web Client)

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.