JSFiddle - React, Tailwind, and code Playground

by designworksinteractive

HTML

<script src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.1.min.js"></script>
<title>Google Maps Multiple Markers</title> 

<body>
  <div id="map" style="width: auto; height: 600px;"></div>

  <script type="text/javascript">
    var locations = [
      ['London Eye ', 51.503510, -0.119434, type: 'info', 3],
      ['Charing Cross', 51.507383, -0.127202, type: 'info', 2],
      ['Kings Cross Station', 51.530616, -0.123125, type: 'info', 1]
        
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 3,
      center: new google.maps.LatLng(51.530616, -0.123125),
      mapTypeId: google.maps.MapTypeId.TERRAIN
    });


    var infowindow = new google.maps.InfoWindow();

    var marker, i;
    var markers = new Array();

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
           map: map
   

          });

      markers.push(marker);

      google.maps.event.addListener(marker, 'mouseover', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }

    function AutoCenter() {
      //  Create a new viewpoint bound
      var bounds = new google.maps.LatLngBounds();
      //  Go through each...
      $.each(markers, function (index, marker) {
      bounds.extend(marker.position);
      });
      //  Fit these bounds to the map
      map.fitBounds(bounds);
    }
    AutoCenter();

  </script> 
</body>