[GIS] map extent to show specific country

google mapsjavascriptopenlayers-2

I use openlayers in my web app.I want to set map extent on specific country to show cities of that country but i don't know which option of map can show specific country in map!.
How can i show specific country on map and can show cities of that country?
To setting map on specific bound when i use below code i can set extent to desire extent!

var bounds = new OpenLayers.Bounds();
    bounds.extend(new OpenLayers.LonLat(8.91,55.18).transform(new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')));
    bounds.extend(new OpenLayers.LonLat(16.19,56.22).transform(new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')));
    map = new OpenLayers.Map('map_element', {
        projection: new OpenLayers.Projection('EPSG:900913'),
        zoomToExtent:bounds
  });
map.setCenter(new OpenLayers.LonLat(-1.788, 53.571).transform(
    new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')
), zoom);

But when i use zoomToExtent and zoomTo function map can't show my desire bound!

var bounds = new OpenLayers.Bounds();
    bounds.extend(new OpenLayers.LonLat(8.91,55.18).transform(new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')));
    bounds.extend(new OpenLayers.LonLat(16.19,56.22).transform(new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')));
    map = new OpenLayers.Map('map_element', {
        projection: new OpenLayers.Projection('EPSG:900913')
  });
map.zoomTo(10);
map.zoomToExtent(bounds);

why in the above code i can't zoom to desire bound?

Best Answer

Check out this question and i think 3rd comment is the answer which u are looking for...

I had similar problem when using cached layers with fixed zoomlevels. zoomToExtent didn't work. I used map.setCenter(lonlat,zoomlevel) instead. I guess it had something to do with the fact that open layers couldn't zoom to that exact extent because it didn't match any zoomlevel. – Voooza Sep 26 '11 at 17:01