We consider the stochastic optimal control problem for the dynamical system of the stochastic differential equation driven by a local martingale with a spatial parameter. Assuming the convexity of the control domain, we obtain the stochastic maximum principle as the necessary condition for an optimal control, and we also prove its sufficiency under proper conditions. The stochastic linear quadratic problem in this setting is also discussed.