Actually, there are quite a few things you can do to avoid getting ambushed. Firstly, enemies on the map can't enter spaces where villages, castles or Dungeons are, so before moving one of your groups around the map, make sure the other ones are in a safe location. Secondly, if you open the menu while on the world map, you will see a command called Wait. This will let you pass some time, causing an enemy that may ambush you to move to a better position.