title: OpenLayers 3: Zoom map to coordinates in array
body: <p>I need to zoom my OpenLayers map (which uses a Google Maps baselayer) to fit all of a given list of coordinates into the view.</p>
  
  <p>I've stored the coordinates in an array of longitude and latitude pairs named <code>pointsDecimal</code> which looks like this:</p>
  
  <pre><code>pointsDecimal: Array[50]
    0: 148.77638
    1: -34.491728
    2: 148.77896
    3: -34.492302
    4: 148.778090711323
    ...
  </code></pre>
  
  <p>Even-numbered indices (0, 2, 4 etc) are longitude, and odd-numbered indices (1, 3, 5 etc) are latitude.</p>
  
  <p>This is the code I'm trying to use:</p>
  
  <pre><code>map.getView().fit(pointsDecimal, map.getSize());
  </code></pre>
  
  <p>But for some reason this puts me at maximum zoom level at the coordinates [0,0] - in the Gulf of Guinea, not in southeastern New South Wales where I'd like to be!</p>
  
  <p>I know this would be much easier if I was using an OpenLayers source (e.g. <code>source.getExtent()</code>) in place of my <code>pointsDecimal</code> array, but this is not an option in this case for reasons I won't go into right now - I can only use the array.</p>
  
  <p>Can anyone give me any hints please?</p>
  
  <p><strong>EDIT:</strong> I think I'm nearly there, thanks to Anupam. This is what I have now:</p>
  
  <pre><code>var extent = [pointsLongMin,pointsLatMin,pointsLongMax,pointsLatMax];
  map.getView().fit(extent,map.getSize());
  </code></pre>
  
  <p>The values I'm passing to the array are as follows:</p>
  
  <pre><code>pointsLongMin: 148.771162
  pointsLatMin: -34.5029736405108
  pointsLongMax: 148.77896
  pointsLatMax: -34.491728
  </code></pre>
  
  <p>But I'm still getting dumped out in the ocean at [0,0]. What am I doing wrong here?</p>