[GIS] How to have two OpenLayers maps on the same page

openlayers-2

Specifically, my question is: how to assign the maps to different divs? In my page it kept placing the two maps under each other, although I defined the divs to be horizontally aligned.
So I have been searching for the answer to this question, when I discovered it by mistake, and I think it is not obvious so I thought I might share it.

Best Answer

Well, this is quite simple: the first parameter in the Map constructor is the id of the div! Thats all.
So in the javascript code:

var firstMap = new OpenLayers.Map("first_Map", { });
var secondMap = new OpenLayers.Map("second_Map", { });

and the html code:

<div id="first_Map" ></div>
<div id="second_Map" ></div>