Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
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

 
discard

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.