Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working with MapServer/Postgis using OpenLayers to display map! I'm trying setCenter map but it not working! My code:

var bounds = new OpenLayers.Bounds(107.567139, 12.326586, 108.258591,
var options = {
    controls : [],
    maxExtent : bounds,
    maxResolution : 0.0010217594533836,
    projection : "EPSG:4326",
    units : 'degrees',
    allOverlays : true

map = new OpenLayers.Map('map', options);
//Declare some layers wms

map.addControl(new OpenLayers.Control.LayerSwitcher({
    'ascending' : false
map.addControl(new OpenLayers.Control.PanZoomBar({
    position : new OpenLayers.Pixel(2, 15)
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({
    element : $('location')
map.setCenter(new OpenLayers.LonLat(12.67812, 108.04401), 5);

Somebody can help me! Thanks!!!

share|improve this question

You just put the center coordinates in wrong order. Longitude should come first and then the latitude. In your code, the point is out of the maxExtent you set in map options.

share|improve this answer

I have an extra (). Like this:

map.setCenter((new OpenLayers.LonLat(160000,485000)), 2);
share|improve this answer

Could be a problem with the map coordinate

var center = new OpenLayers.LonLat(12.67812, 108.04401);
center.transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
share|improve this answer
Thanks for reply! But it's not working! You can give me a demo of setCenter in OpenLayers! – Si Do Dinh Jan 29 '13 at 11:55
Thanks to everyone! I sloved problem! It's map.setCenter(new OpenLayers.LonLat(108.04401, 12.67812), 5); Instead map.setCenter(new OpenLayers.LonLat(12.67812, 108.04401), 5); – Si Do Dinh Jan 29 '13 at 12:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.