title: Google maps, pass map to function
body: <p>I'm trying to move to the first market put in the map, but i can't make it work.</p>
  
  <p>First, I store the marker in one array, at this point I only need to the first, later I will create the entire logic.</p>
  
  <p>here is the code:</p>
  
  <pre><code> var geocoder;
     var map;
     var markersArray = [];
  
   //Initialization
   function initMap() {
  
     var map = new google.maps.Map(document.getElementById('map'), {
       zoom: 16,
       center: {lat: 14.601313, lng: -90.519114},
     });
  
     map.addListener('click', function(e) {
       placeMarkerAndPanTo(e.latLng, map);
     });
  
   }
  
   //Add marker function
   function placeMarkerAndPanTo(latLng, map) {
        marker = new google.maps.Marker({
       position: latLng,
       map: map
     });
      markersArray.push(latLng);
      map.panTo(latLng);
   }
  
   //Button: click move to the very first marker
   $(document).ready(function(){
       $('#MyButton').click(function(){
   alert("click");
         alert(markersArray[0].lat());
         map.panTo(markersArray[0].lat(),markersArray[0].lng());
       });
     });
  </code></pre>
  
  <p>Fix:</p>
  
  <pre><code> $(document).ready(function(){
       $('#MyButton').click(function(){
         if (markersArray.length &gt; 0){
  
           map.setCenter(markersArray[0]);
       }
         //map.fitBounds(markersArray[0].lat(),markersArray[0].lng());
       });
     });
  </code></pre>