The modern countries didn't always exist when our ancestors were born. Part of what was once Denmark is now part of Germany, part of what is now Romania was part of Austria, etc. They had to get official permission to emigrate to other areas that are now Germany. And it has changed in our day too. So all of that is naturally confusing. Then, when they did emigrate, their names changed more to fit with the local spellings.
Many of our ancestors could not read or write, which compounds the problem of spelling their names. It wasn't until relatively recently in history that most people were literate. So the name on official documents is pretty much what the official decided it was....Meier, Mayer, Maier, Meyer, or....
I've noticed in my tree that some of the German females have an "in" ending to their last names. Becker becomes Beckerin for them, for instance, while the males stay as Becker.