Identify objects (bus) on the map based on coordinates (lat, lon)
Have the app record the GPS location once per second, save it, and once every 30 seconds, update that trace of the locations over the past 30 seconds.  Or, just upload the location every second.  The bandwidth requirements for that are small.  Then, if you have multiple users in the same location (within a fixed radius, say within 100 ft of each other), and with a velocity within some fixed range (say, between 20-60 mph), declare them to be on a bus together.  That should be fast, and doesn't require knowing the number of buses.

This problem doesn't need a solution with a fancy algorithm; straightforward solutions should suffice.