[GIS] Change center of map in OpenLayers dynamically

openlayers-2

Is there a way to change the center of the map in OpenLayers dynamically? For example on button click. It would be too much to ask a "fly to" functionality and as I read this is offered in OpenLayers 3 but currently I am using OpenLayers 2 and we don't plan to migrate.

I tried something as simple as:

map.setCenter(22.191969,38.784336,7);

but this doesn't work..

Best Answer

OpenLayers.Map.setCenter has a different signature:

setCenter: function(lonlat,
                    zoom,
                    dragging,
                    forceZoomChange)

Where lonlat is an OpenLayers.LonLat object.

You can also use moveTo which has a similar paramaters list.