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));

}
3

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...

1
  • 1
    thank you, this works for me. but shouldn't it also work with the two commands seperated? – ABLX May 9 '12 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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