JSFiddle - React, Tailwind, and code Playground

by designworksinteractive

HTML

<script src="https://maps.google.com/maps/api/js"></script>
<div id="map" style="width: 500px; height: 400px;"></div>
<div>
  <a id="1" href="#">Go to 1</a>
  <br>
  <a id="2" href="#">Go to 2</a>
  <br>
  <a id="3" href="#">Go to 3</a>
  <br>
  <a id="4" href="#">Go to 4</a>
  <br>
  <a id="5" href="#">Go to 5</a>
  <br>
</div>

JavaScript

var labels = '123456';
var labelIndex = 0;

var locations = [
  ['Bondi Beach', -33.890542, 151.274856, 4],
  ['Coogee Beach', -33.923036, 151.259052, 5],
  ['Cronulla Beach', -34.028249, 151.157507, 3],
  ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
  ['Maroubra Beach', -33.950198, 151.259302, 1]
];

var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 10,
  center: new google.maps.LatLng(-33.92, 151.25),
  mapTypeId: google.maps.MapTypeId.ROADMAP
});

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

var marker, i;
var markers = [];
for (i = 0; i < locations.length; i++) {
  var marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map,
    label: labels[labelIndex++ % labels.length],
  });
  markers.push(marker);
};

$("a").click(function() {
  // google.maps.event.trigger(markers[this.id]);
  map.panTo(markers[this.id-1].getPosition());
  map.setZoom(14);
  return false;
});