I'll try to explain my application and the problem.

My application gets a position for a zip code and receives a Lat/Long position, then I'm looking for all points around this position and show them.(This works fine)

Now I want to try to show a user his zipcode position at the center of the map, but I also want to specify the correct zoom level, so that the user can see all points around this point. (it's not limited by the distance)

Is this possible?

My minLat,maxLat,minLng,maxLng looks like this :

Array ( [minLng] => 8.381 [maxLng] => 9.15259 [minLat] => 49.5103735 [maxLat] => 50.06762 )



map.setCenter(new OpenLayers.LonLat(center.lon,center.lat) // Center of the map
                new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
                new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
                ), config.zoom // Zoom level
    map.zoomToExtent(new OpenLayers.Bounds(config.bounds.minLng,config.bounds.minLat,config.bounds.maxLng,config.bounds.maxLat).transform(epsg4326));

I have added the html of the function.


You can use openlayers bounds to set extent and then zoom your map to extent using map.zoomToExtent() or map.zoomToMaxExtent()

Here's an example:

map.zoomToExtent(new OpenLayers.Bounds(minLng,minLat,maxLng,maxLat).transform("EPSG:4326", "EPSG:900913"))
  • 1
    Hello, thx for you answer, but it doesn't work :/ I have added my function calls to the main post. Before i forget to say, with map.zoomToExtent i see only the ocean. Here the result of map.getCenter() OpenLayers.LonLat.OpenLayers.Class.initialize {lon: 8.75207, lat: 49.76202, lon: 0, lat: 0, initialize: function…} lat: 49.76202 lon: 8.75207 proto: Object Or the Map turn blue, i don't know :/ – demonking Oct 22 '13 at 19:34
  • You are not projecting your OpenLayers.Bounds correctly. I'll update the example to use transform correctly. Note that if you see only the ocean after a zoom, it usually mean that you zoomed with lon/lat coordinates on a SphericalMercator map. Zoom out and you will notice that you are in the middle of the Gulf of Guinea. – Julien-Samuel Lacroix Oct 22 '13 at 19:37
  • Thx a lot :D Now it works fine And yes you were right with the Gulf of Guinea ;) – demonking Oct 22 '13 at 20:55

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.