Solution 1:

"Legend" implies that its entries are generics, as with terrain types on a map, while "key" implies that its entries are specific, as with one symbol designating the Museum of Natural History, another the Metropolitan Museum of Art, etc. Generally, nobody is going to get real mad no matter which you use. It doesn't matter where they're located.

Solution 2:

A legend is a caption, a title or brief explanation appended to an article, illustration, cartoon, or poster.
A key is an explanatory list of symbols used in a map, table, etc.

Legend is more generic, while key is more specific. Neither word implicates anything about the location of the text/list.

Solution 3:

A "Caption" used to be a box you put at the top of a map, hence the "Cap" part.

The "Legend" is the explanatory information within a Caption that allows you to understand how to use the map, especially the Keys. It is a syllogistic synopsis, a short story if you will.

The "Keys" are the symbols and numbers within the Caption that the Legend explains.

Somehow the two got mixed up over the centuries.

Imagine if you had a Caption with Keys but no Legend to explain what they mean. These types of maps are actually all too common. They are fun and challenging but sometimes impossible to understand because you have to be a bit of a cryptologist to decipher what the symbols mean sometimes. We've all seen the dotted line which represents a trail, a straight line a road, a wavy line a river, a circle with a triangle in it a campground, a skull and bones something dangerous etc.

Now imagine if you had a Caption with a Legend but no symbols. These maps exist too, as the explanation could be about shaded areas on the map with no need for designating symbols.

Somehow the Legend came to be called the "Key", which is bizarre, as if the map had a single symbol. Just as odd, some Captions are called the "Compass" which is actually the Rose Compass, which is a diagram explaining the cardinal directions relevant to the map.