I would like the get the center (coordinates) of the current view. I need it for the geoserver print module.

I've found the code var center= ol.extent.getCenter({}); but it unfortunately doesn't work. Furthermore I've found a code in the API (getview.getcenter()), but it only shows the initial center and it is not changing when I explore on the map.

This is my code, it works fine except the center params... It gives back tha same values everytime.

var configs = {

    "layout":"A4 portrait",
    "outputFilename": "valami",
     {baseURL: 'xy', 
            singleTile: false, 
            type: 'OSM', 
            maxExtent: [-20037508.3392,-20037508.3392,20037508.3392,20037508.3392], 
            tileSize: [256, 256], 
            extension: 'png',
            opacity: 1,
            resolutions: [156543.0339, 78271.51695, 39135.758475, 19567.8792375, 9783.93961875, 4891.969809375, 2445.9849046875, 1222.99245234375, 611.496226171875, 305.7481130859375, 152.87405654296876, 76.43702827148438, 38.21851413574219, 19.109257067871095, 9.554628533935547, 4.777314266967774, 2.388657133483887, 1.1943285667419434, 0.5971642833709717] 
        "comment":" ",
        "scale": 1000000,
    "legends": [
            "classes": [
                    "icons": [
                    "name": "",
                    "iconBeforeName": true
            "name": "utak"

 var printUrl= 'xy?spec='+JSON.stringify(configs);
  • Are you accessing getCenter in some map change event callback? – John Powell May 18 '15 at 12:22
  • Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Please check out our short tour to learn about our focussed Q&A format. – PolyGeo Feb 18 '19 at 4:06

For OpenLayers 2 try



Or OpenLayers 3 use


http://openlayers.org/en/v3.5.0/apidoc/ol.Map.html#getView http://openlayers.org/en/v3.5.0/apidoc/ol.View.html#getCenter

  • Thank You for the answer, but Your solution is returns the initial center, and this is a predefined value. I need the current center, so I would like to get the actual view's center coordinates. – user52288 May 19 '15 at 15:30
  • Which version of Openlayers are you using? – Guy May 20 '15 at 10:33
  • Openlayers 3.3.0 – user52288 May 24 '15 at 21:31
  • @user52288 using the map.getView().getCenter() should get the current center of the ol.Map object called "map". Are you sure you're calling the view correctly? It would help if you could include a snippet or link to some code. – Guy Jun 1 '15 at 15:32
  • i've written my code, could you check it? thanks!! – user52288 Jun 4 '15 at 2:28

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.