This paper proposes an online learning collaborative method for traffic forecasting and routing optimization. It designs a system architecture that integrates traffic and vehicle data using technologies like IoT, cloud computing, and cyber-physical systems. An online learning data-driven model is constructed using model learning and parameter learning to extract knowledge from historical and real-time data. This model and a collaborative optimization mechanism enhance coordination between road segments and vehicles by combining short-term forecasting and routing optimization. A case study of this method in Xi'an City shows it can effectively reduce travel time compared to other methods.