[GIS] Why doesn’t OpenLayers zoom

javascriptopenlayers-2

I've got a little problem with OpenLayers.
I've a simple function which sets the center of the map to the position of the user – this works fine. But: it should also zoom – which, for an unknown reason, don't work.

Any ideas?

function gotSomeLocation(position){
    var lat = position.coords.latitude;
    var long = position.coords.longitude;
    map.zoomTo(18);
    alert("Lokalisiert!");
    map.setCenter(tCoord(long, lat));

}

Best Answer

use sth. like this:

map.setCenter(new OpenLayers.LonLat(long, lat),10);

.

Usage:

map.setCenter(lonlat, zoom);

you dont also need to use map.zoomTo(18);

setCenter

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

Set the map center (and optionally, the zoom level).

Parameters
lonlat  {<OpenLayers.LonLat>|Array} The new center location.  If provided as    
array, the first value is the x coordinate, and the 2nd value is the y coordinate.
zoom    {Integer} Optional zoom level.
dragging    {Boolean} Specifies whether or not to trigger movestart/end events
forceZoomChange {Boolean} Specifies whether or not to trigger zoom change events (needed on baseLayer change)

i hope it helps you...