Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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'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.setCenter(tCoord(long, lat));

share|improve this question
up vote 3 down vote accepted

use sth. like this:

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



map.setCenter(lonlat, zoom);

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


setCenter: function(    lonlat,
    forceZoomChange )

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

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