# TfNSW real-time map

**URL:** <https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84>\
**Category:** Brag\
**Created:** [April 21, 2016, 4:31pm UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84 "2016-04-21T16:31:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [April 21, 2016, 4:31pm UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/1 "2016-04-21T16:31:57Z")

</div>

## [TfNSW real-time map](http://jxeeno.net.au/tfnsw/map)

 ![](https://us1.discourse-cdn.com/flex019/uploads/nsw/original/1X/4aeb6d122265eea3ddf7aa65e1ee8e844b0b0c06.png)

So, it’s been a fairly exciting week for all data geeks alike! I’ve been working on a pretty simple real-time map, currently polled once ~~a minute from~~ once every 15 seconds from the TfNSW APIs.

~~At the moment, it only supports trains (that’s Sydney Trains and NSW TrainLink services). Once a few issues are resolved by the TfNSW Open Data team, I’ll include buses, light rail and ferries. Hopefully, I’ll also be able to increase the frequency of data polling.~~ Trains, buses, light rail and ferries are now all on the map 🙂

~~Stopping patterns for each service is also coming soon – pending the resolution of [this](http://opendata.transport.nsw.gov.au/forum/t/realtime-gtfs-schedules-download-inconsistent/64) issue.~~

**Known issues:**

- NSW TrainLink services that are travelling within Sydney Trains’ network currently shown with duplicate markers. Logic is required to filter out NSW Trains data when it enters the metropolitan network since GPS data is delayed by ~5 mins and isn’t always accurate.
- Hunter Line services are not labeled.
- Clicking on marker shows the full extent of the route. It should be truncated to start and end station for the trip.

**Fixed issues**

- Stopping patterns are missing in action pending resolution of [this](http://opendataforum.transport.nsw.gov.au/t/realtime-gtfs-schedules-download-inconsistent/64) issue.

Feedback & suggestions are always appreciated 😃

Link: [TfNSW real-time map](http://jxeeno.net.au/tfnsw/map)

---

<div class="post-metadata">

**Author:** ![Nirving](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/nirving/32/218_2.png) [@Nirving](https://opendataforum.transport.nsw.gov.au/u/Nirving)\
**Post date:** [April 21, 2016, 7:23pm UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/2 "2016-04-21T19:23:24Z")

</div>

Morning,  
Congratulations on your site, it looks great.

I am trying to get my own version up and running as well and I am wondering if I can ask you question about getting the data from the API. This is something that I have been trying to wrap my head around for a while.

When a client accesses your site, do you send that request through to the tfsnw API? So say 10 people access your site, is that 10 requests to your site and then 10 requests to tfnsw, or 10 requests to your site and then 1 request to tfsnw, with it those requests being server out of say a cache?

For example my idea is this.

1. Have a background poller getting the data from the API and putting into a cache, say disk, every minute or so, already in the format I need to send to the client.
2. All requests for my API, use that cache version.

This way I am not opening my server to manage a 1 to 1 relationship between the client and the tfnsw API and I think I will win overall as I have reduced the overall processing time as I am not proxying the client request.

Any thoughts on this approach would be appreciated.

---

<div class="post-metadata">

**Author:** ![tdnetto](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/tdnetto/32/224_2.png) [@tdnetto](https://opendataforum.transport.nsw.gov.au/u/tdnetto)\
**Post date:** [April 21, 2016, 10:40pm UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/3 "2016-04-21T22:40:01Z")

</div>

This is fantastic. Any chance of sharing the github?

It seems very mature already - you are already detecting and reporting outages.

How are you making the coloured boxes with the initials in them? Its a design style I see everywhere, but I have no idea how it is typically done these days (or what it is called).

---

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [April 21, 2016, 11:02pm UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/4 "2016-04-21T23:02:42Z")

</div>

> [@Nirving](#):
>
> For example my idea is this.1. Have a background poller getting the data from the API and putting into a cache, say disk, every minute or so, already in the format I need to send to the client.2. All requests for my API, use that cache version.

That’s basically what I have going! I have a cron job running once a minute to download the latest data and loading it onto a database. I’ll probably need to make it more sustainable as I’ve reached almost 2 million rows in just the past few days.

The map then calls on an endpoint on my own server that queries my own API which only looks up data on my own database.

This is definitely the best approach currently. I’ve been chatting with Yvonne and it looks like there are a few issues that the may need to be ironed out on their end before we can make more frequent requests. I had it set to download all modes of transport every half a minute (i.e. 5\*2 = 10 per minute) and the servers weren’t too happy… but they’re working on it 🙂

---

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [April 22, 2016, 1:00am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/5 "2016-04-22T01:00:44Z")

</div>

Hey Tom!

> [@tdnetto](#):
>
> This is fantastic. Any chance of sharing the github?

I do certainly plan to eventually. I’m not a huge fan of the current code (it’s rather cobbled together, as is all rapid prototyping code), so once I clean it up a bit… I’ll pop it up.

> [@tdnetto](#):
>
> It seems very mature already - you are already detecting and reporting outages.

It just happened that the service has been hitting some “teething issues” over the past few days… which meant implementing the outage message was actually good for debugging! If the last two data updates have failed, it will show the TfNSW outage message.

> [@tdnetto](#):
>
> How are you making the coloured boxes with the initials in them? Its a design style I see everywhere, but I have no idea how it is typically done these days (or what it is called).

It’s CSS 🙂 No idea what it’s called though… but TfNSW seems to love it.

```auto
.icon {
    color: white;
    background: #777;
    border-radius: 12px;
    border: 2px solid white;
    height: 24px;
    width: 24px;
    margin-left: -12px;
    margin-top: -12px;
    text-align: center;
    line-height: 22px;
    font-weight: bold;
}
.sydneytrains.icon.line-T3 {
    background: #f25323;
}

```

---

<div class="post-metadata">

**Author:** ![tdnetto](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/tdnetto/32/224_2.png) [@tdnetto](https://opendataforum.transport.nsw.gov.au/u/tdnetto)\
**Post date:** [April 22, 2016, 2:02am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/6 "2016-04-22T02:02:19Z")

</div>

Cheers Kenneth! Small world 🙂

Lemme know when you push to github, super keen to see your stack xD

How is your memory / CPU load going with all the parsing?

---

<div class="post-metadata">

**Author:** ![jason120au](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jason120au](https://opendataforum.transport.nsw.gov.au/u/jason120au)\
**Post date:** [April 27, 2016, 6:34am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/7 "2016-04-27T06:34:38Z")

</div>

How were you able to get the data in regards to what train is serving a particular route ie 8 cars A Set (Waratah)?

---

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [April 27, 2016, 8:01am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/8 "2016-04-27T08:01:07Z")

</div>

> [@jason120au](#):
>
> How were you able to get the data in regards to what train is serving a particular route ie 8 cars A Set (Waratah)?

It’s part of the Trip ID (read the documentation [here](https://opendata.transport.nsw.gov.au/content/dam/apiportal/transportnsw/docs/TfNSW_Realtime_Train_Technical_Doc.pdf)).

e.g. you’ll notice `A.8` in the trip ID `175N.922.106.120-20160427.A.8.41509951` denotes that this is an A set with 8 carriages.

Similarly, `H.8` in `282P.922.106.88-20160427.H.8.41507879` indicates this is an H set (Oscar) with 8 carriages.

edit: corrected to H set, not M set.

---

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [May 4, 2016, 1:06pm UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/9 "2016-05-04T13:06:13Z")

</div>

So, I busted the storage capabilities of my old server last week. Finally got around to fixing it tonight.

As a bonus, I’ve also added live bus and ferry data 🙂 Bus timetable is pending [this](http://opendata.transport.nsw.gov.au/forum/t/gtfs-bundle-for-type-schedule-is-not-available-for-agency-buses).

\<img src=“[//cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex019/uploads/nsw/original/1X/192e3fdaf497746511f4d5c1ef4d0ebc140657b0.png](https://us1.discourse-cdn.com/flex019/uploads/nsw/original/1X/192e3fdaf497746511f4d5c1ef4d0ebc140657b0.png)” width=“690” height=“456”

---

<div class="post-metadata">

**Author:** ![Butterbox472](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/butterbox472/32/205_2.png) [@Butterbox472](https://opendataforum.transport.nsw.gov.au/u/Butterbox472)\
**Post date:** [May 10, 2016, 11:33am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/10 "2016-05-10T11:33:22Z")

</div>

The data seems frozen as of around 5pm on 9th May.

---

<div class="post-metadata">

**Author:** ![BenCousins](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/bencousins/32/203_2.png) [@BenCousins](https://opendataforum.transport.nsw.gov.au/u/BenCousins)\
**Post date:** [May 11, 2016, 2:32am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/11 "2016-05-11T02:32:08Z")

</div>

> [@Butterbox472](#):
>
> The data seems frozen

Ah so that’s why I couldn’t find something I was after earlier.

---

<div class="post-metadata">

**Author:** ![andrew](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/andrew/32/201_2.png) [@andrew](https://opendataforum.transport.nsw.gov.au/u/andrew)\
**Post date:** [August 1, 2016, 12:41pm UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/12 "2016-08-01T12:41:09Z")

</div>

> [@jxeeno](#):
>
> Feedback & suggestions are always appreciated 😃

This is awesome! Thanks for sharing.

> [@jxeeno](#):
>
> I do certainly plan to eventually. I’m not a huge fan of the current code (it’s rather cobbled together, as is all rapid prototyping code), so once I clean it up a bit… I’ll pop it up.

I’m keen to see that too, even if it’s messy.

I tried to build pretty much this exact site for GovHack (I didn’t know about your version until now) but didn’t get far enough along with it.

I was building it on Mapbox GL JS rather than Leaflet though (client can load and show all route paths via vector tiles, the GTFS-R protobufs were downloaded directly from the client and decoded within the client JS application, and a custom basemap design to enhance the data display), with the goal to animate the markers so they look real time using [GitHub - misterfresh/mapbox-animation: Animate a Geojson Source](https://github.com/misterfresh/mapbox-animation) (my idea was to extrapolate out from the location given in the feed along the route polygon based on the speed and direction (forward/backward) to a maximum of the refresh interval using something like [https://github.com/Turfjs/turf/tree/master/packages/turf-line-slice-along](https://github.com/Turfjs/turf/tree/master/packages/turf-line-slice-along) to de the extrapolate along a line, at least for buses and ferries. Trains since I think they are based on section midpoint might need to be treated slightly differently.

---

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [January 4, 2017, 4:24am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/13 "2017-01-04T04:24:09Z")

</div>

Thought I’d spend the Xmas/NY overhauling the map 🙂 The updated map can be found at [anyt.rip/map](http://anyt.rip/map)

**Changelog**

- Refresh rate is now ~15-30s for all modes except buses. Buses is ~1-2 mins due to large dataset.
- Map should now correctly show the stopping pattern of added trips and runs with transpositions
- Marker movement is animated
- Ability to select which modes to display (buses hidden by default to reduce lag).
- Click on a vehicle to highlight a particular trip and get additional information
- Now shows route and stop locations
- Vehicle direction arrow for all modes with bearing data (except Sydney Trains).

 ![](https://us1.discourse-cdn.com/flex019/uploads/nsw/original/1X/0aabb5403a74b77520b68ea2208d4f7846df6d1d.jpg)

---

<div class="post-metadata">

**Author:** ![yvonne.lee](https://avatars.discourse-cdn.com/v4/letter/y/c37758/32.png) [@yvonne.lee](https://opendataforum.transport.nsw.gov.au/u/yvonne.lee)\
**Post date:** [January 10, 2017, 7:04am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/14 "2017-01-10T07:04:01Z")

</div>

Looking great @jxeeno. Can you update your logos of the services to the official ones? Including the ‘burnt’ orange for the T for regional trains (rather than the non approved purple R?)

> **[Marketing | TfNSW Open Data Hub and Developer Portal](https://opendata.transport.nsw.gov.au/marketing)**
>
> Transport for NSW's Open Data Portal

---

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [January 10, 2017, 8:54am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/15 "2017-01-10T08:54:00Z")

</div>

Will do @yvonne.lee.

Is the burnt orange roundel OK for describing regional services (coach and trains) collectively?

---

<div class="post-metadata">

**Author:** ![yvonne.lee](https://avatars.discourse-cdn.com/v4/letter/y/c37758/32.png) [@yvonne.lee](https://opendataforum.transport.nsw.gov.au/u/yvonne.lee)\
**Post date:** [January 10, 2017, 10:37pm UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/16 "2017-01-10T22:37:32Z")

</div>

Hmmm I _think_ so. Collectively I think it’s known as NSW Trainlink but the mode icons should be the Coach (purple) and Train (Burnt Orange).

I grabbed the below from our brand guidelines. Note you can also use the pictograms. Usually the letters are used for Wayfinding but has become the common way for app developers to indicate the modes and is recognisable by our customers.

![](https://us1.discourse-cdn.com/flex019/uploads/nsw/original/1X/b2fa211394d6098f853b82956fd2c7405740e6f2.PNG)  
 ![](https://us1.discourse-cdn.com/flex019/uploads/nsw/original/1X/c34cca1897eb15354315ad9078bafeb9a31148b4.PNG)

---

<div class="post-metadata">

**Author:** ![PeterL2F](https://avatars.discourse-cdn.com/v4/letter/p/9fc348/32.png) [@PeterL2F](https://opendataforum.transport.nsw.gov.au/u/PeterL2F)\
**Post date:** [January 11, 2017, 9:13am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/17 "2017-01-11T09:13:38Z")

</div>

Great work! would be cool to see a refresh timer next to “last updated” to give the user a better picture on when the next data set will be loaded

---

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [January 27, 2017, 8:21am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/18 "2017-01-27T08:21:05Z")

</div>

Thanks for the suggestion, @PeterL2F! I’ve now updated the “last updated” list to include a timer:

![](https://us1.discourse-cdn.com/flex019/uploads/nsw/original/1X/1d2c4a3c9b3b5531b93e16a369a75e3033a64639.png)

---

<div class="post-metadata">

**Author:** ![hkotfnsw](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hkotfnsw](https://opendataforum.transport.nsw.gov.au/u/hkotfnsw)\
**Post date:** [January 31, 2017, 3:56am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/19 "2017-01-31T03:56:17Z")

</div>

Nice! It looks very slick.

I remember you mentioned in another post that you are putting some documents together. Will they be publicly available?

---

<div class="post-metadata">

**Author:** ![jxeeno](https://sea1.discourse-cdn.com/flex019/user_avatar/opendataforum.transport.nsw.gov.au/jxeeno/32/210_2.png) [@jxeeno](https://opendataforum.transport.nsw.gov.au/u/jxeeno)\
**Post date:** [February 3, 2017, 12:29am UTC](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84/20 "2017-02-03T00:29:58Z")

</div>

> [@hkotfnsw](#):
>
> I remember you mentioned in another post that you are putting some documents together. Will they be publicly available?

Thanks 🙂 I’ll look into releasing a public version. I currently has a fair amount of internal stuff in it as well.

[Next page](https://opendataforum.transport.nsw.gov.au/t/tfnsw-real-time-map/84.md?page=2)
