Skip to content

Instantly share code, notes, and snippets.

@runarorama
Created September 22, 2014 20:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runarorama/e2c3a206c94c00e12ed7 to your computer and use it in GitHub Desktop.
Save runarorama/e2c3a206c94c00e12ed7 to your computer and use it in GitHub Desktop.
Interactive location plot of busses in Iceland
Block[{},
BusData[bus_] :=
"results" /. First[Import[StringJoin["http://apis.is/bus/realtime?busses=", bus], "JSON"]];
AllBusData := "results" /. First[Import["http://apis.is/bus/realtime?busses=", "JSON"]];
Dist[{x_ -> y_, a_ -> b_}] := (Flatten[{#1, a -> b}] & ) /@ y;
CommaSep[xs_] := StringTemplate["<*Row[`1`,\",\"]*>"][xs];
Busses[bus_] := Cases[Flatten[Dist /@ BusData[CommaSep[bus]], 1],
{__, "to" -> to_, __, "x" -> x_, "y" -> y_, "busNr" -> n_} ->
Tooltip[GeoPosition[{x, y}], n*to], Infinity];
AllBusses := "busNr" /. AllBusData;
Manipulate[
GeoListPlot[
Busses[{Bus}],
GeoBackground -> GeoStyling["StreetMap"],
ImageSize -> Large,
GeoRange -> City,
GeoRangePadding -> Quantity[4, "Kilometers"]],
{Bus, AllBusses},
{City, {
Entity["City", {"Reykjavik", "Hofudhborgarsvaedhi", "Iceland"}],
Entity["City", {"Kopavogur", "Hofudhborgarsvaedhi", "Iceland"}],
Entity["City", {"Hafnarfjordhur", "Hofudhborgarsvaedhi", "Iceland"}],
Entity["City", {"Mosfellsbaer", "Hofudhborgarsvaedhi", "Iceland"}],
Entity["City", {"Akureyri", "NordhurlandEystra", "Iceland"}],
Entity["Airport", "BIKF"]}}]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment