Duplicated Realtime Buses at Same Location

Hi, we need to display realtime bus locations on a map. It appears that the the realtime bus vehicle positions and trip updates also contain “future” buses - buses with trips in the future.

I have seen two cases for future trips: sometimes you get two buses at the exact location, where one is the currently running bus and one is the planned/future bus; sometimes you get just one future bus (e.g. school buses that are about to pick up children).

For the first case, how do you remove the duplication at the same location? For the second case, it is valid on the map so we want to keep it.

One obvious way is to detect records with duplicated latitude/longitude. But is there a better way?

For instance, at around 5pm today, the following two realtime vehicle position records have the exact same location, one is currently running and one is in the future (where the start-time is 5:41pm). They have the exact same location so two duplicated records on the map, which isn’t nice:

{
			"id": "11954_143975992_2440_230_1",
			"is_deleted": false,
			"trip_update": null,
			"vehicle": {
				"trip": {
					"trip_id": "317950",
					"route_id": "2440_230",
					"direction_id": 0,
					"start_time": "17:41:00",
					"start_date": "20170210",
					"schedule_relationship": 0
				},
				"vehicle": {
					"id": "11954_143975992_2440_230_1",
					"label": "",
					"license_plate": ""
				},
				"position": {
					"latitude": -33.83195114135742,
					"longitude": 151.23855590820312,
					"bearing": 252,
					"odometer": 0,
					"speed": 2.299999952316284
				},
				"current_stop_sequence": 0,
				"stop_id": "",
				"current_status": 2,
				"timestamp": 1486708558,
				"congestion_level": 0,
				"occupancy_status": 1
			},
			"alert": null
		}, {
			"id": "11954_143975993_2440_230_1",
			"is_deleted": false,
			"trip_update": null,
			"vehicle": {
				"trip": {
					"trip_id": "326981",
					"route_id": "2440_230",
					"direction_id": 0,
					"start_time": "16:56:00",
					"start_date": "20170210",
					"schedule_relationship": 0
				},
				"vehicle": {
					"id": "11954_143975993_2440_230_1",
					"label": "",
					"license_plate": ""
				},
				"position": {
					"latitude": -33.83195114135742,
					"longitude": 151.23855590820312,
					"bearing": 252,
					"odometer": 0,
					"speed": 2.299999952316284
				},
				"current_stop_sequence": 0,
				"stop_id": "",
				"current_status": 2,
				"timestamp": 1486708558,
				"congestion_level": 1,
				"occupancy_status": 1
			},
			"alert": null
		}

You need to decode using the proto file provided by TfNSW. You should then get access to the tfnsw_vehicle_descriptor extension entity with the performing_prior_trip boolean attribute:

entity {
  id: "33553_11671096_2436_606_1"
  vehicle {
    trip {
      trip_id: "300471"
      start_time: "23:05:00"
      start_date: "20170210"
      schedule_relationship: SCHEDULED
      route_id: "2436_606"
    }
    position {
      latitude: -33.817406
      longitude: 151.00581
      bearing: 326
      speed: 0
    }
    timestamp: 1486727710
    congestion_level: UNKNOWN_CONGESTION_LEVEL
    vehicle {
      id: "33553_11671096_2436_606_1"
      tfnsw_vehicle_descriptor {
        air_conditioned: true
        wheelchair_accessible: 1
        performing_prior_trip: true
        special_vehicle_attributes: 0
      }
    }
    occupancy_status: MANY_SEATS_AVAILABLE
  }
}
2 Likes