Catalyzes the methylation of glycine, sarcosine and dimethylglycine to sarcosine, dimethylglycine and betaine, 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 2 S-adenosyl-L-methionine + sarcosine = glycine betaine + 2 H(+) + 2 S-adenosyl-L-homocysteine 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. Amine and polyamine biosynthesis; betaine biosynthesis via glycine pathway; betaine from glycine: step 3/3. Monomer. Belongs to the class I-like SAM-binding methyltransferase superfamily. Glycine N-methyltransferase family.