The current location of the bus can be seen from Google Map, but let's map it by yourself. Let's display it on python using a web map display plugin called folium. The map icon is clickable and can also display detailed information.
realtimebus.py3
from google.transit import gtfs_realtime_pb2
import urllib.request, urllib.error
import folium
import pandas as pd
#GTFS-Public URL of RT(Uno Bus)
url ='http://www3.unobus.co.jp/GTFS/GTFS_RT-VP.bin'
#Declaration of column name
list_df = pd.DataFrame(columns=['id' , 'vehicle_id', 'trip_id','vehicle_timestamp','longitude','latitude','occupancy_status'])
feed = gtfs_realtime_pb2.FeedMessage()
#Data download and format conversion
with urllib.request.urlopen(url) as res: #Data download
feed.ParseFromString(res.read()) #Deserialize protocol buffers
for entity in feed.entity:
tmp_se = pd.Series( [
entity.id, #Vehicle ID
entity.vehicle.vehicle.id, #Vehicle number
entity.vehicle.trip.trip_id, #Route number?
entity.vehicle.timestamp, #Vehicle time
entity.vehicle.position.longitude, #Vehicle latitude
entity.vehicle.position.latitude, #Vehicle longitude
entity.vehicle.occupancy_status #Congestion degree
], index=list_df.columns )
list_df = list_df.append( tmp_se, ignore_index=True )
#Calculate the center point of the map
average_pos = list_df.mean()
#Create a map near the center coordinates
m = folium.Map(location=[average_pos['latitude'], average_pos['longitude']], zoom_start=11)
#Plot each bus(The color is blue)
list_df.apply(lambda row:
folium.Marker(
location=[row['latitude'], row['longitude']],
popup='<table border="1"><tr><th>occupancy_status</th></tr><tr><td>'
+str(row['occupancy_status'])
+'</td></tr></table>',
icon=folium.Icon(color='blue',icon='bus', prefix='fa')
).add_to(m), axis=1)
m
The downloaded real-time location information is plotted on the map
The timing of execution is past 22:30, but the bus is still running. .. ..