[GIS] how to display map center coordinate using OpenLayers

openlayers-2

As far as I know OpenLayers can display our mouse coordinate position. However, I do not know how to display map center coordinate?
Can anyone help me?

Best Answer

The easiest way would be to add an event to the map object so that on moveend some div (or something else) is updated. The map center itself can easily be retrieved from the map object with getCenter. For example:

map.events.on({
        "moveend":function(){
            alert(map.getCenter().toString());
        }
    });