Catalyzes the methylation of glycine and sarcosine to sarcosine and dimethylglycine, respectively, with S-adenosylmethionine (AdoMet) acting as the methyl donor. glycine + 2 S-adenosyl-L-methionine = 2 H(+) + N,N-dimethylglycine + 2 S-adenosyl-L-homocysteine Inhibited by acetate, dimethylglycine and S-adenosyl-L-homocysteine. Optimum pH is 8.8. The activities remain high at more alkaline pH but decrease sharply at the acidic side of the optimal pH. Amine and polyamine biosynthesis; betaine biosynthesis via glycine pathway; betaine from glycine: step 1/3. Amine and polyamine biosynthesis; betaine biosynthesis via glycine pathway; betaine from glycine: step 2/3. Monomer. Belongs to the class I-like SAM-binding methyltransferase superfamily. Glycine N-methyltransferase family.