Industrial robots are widely utilized in the machining of complex parts because of their flexibility. However, their low positioning accuracy and spatial geometric error characteristics significantly limit the contour precision of robot machined parts. Therefore, in the robot machining procedure, an in situ measurement system is typically required. This study aims to enhance the trajectory accuracy of robotic machining through robotic in situ measurement and meta-heuristic optimization. In this study, a measurement-machining dual-robot system for measurement and machining is established, consisting of a measurement robot with a laser sensor mounted at the robot end and a machining robot equipped with a machining tool. In the measuring process, high-precision standard spheres are set on the edge of the machining area, and the high-precision standard geometry is measured by the measurement robot. According to measured geometry information in the local area, the trajectory accuracy for the machining robot is improved. By utilizing the standard radius of the standard spheres and adopting a meta-heuristic optimization algorithm, this study addresses the complexity of the robot kinematics model, while also overcoming local optima commonly introduced by gradient-based iterative methods. The results of the experiments in this study confirm that the proposed method markedly refines the precision of the robot machining trajectory.