JSFiddle - React, Tailwind, and code Playground

by MarkSzs

HTML

<div id="map"></div>
<!--
<div id="right-panel">
  <h2>Results</h2>
  <ul id="places"></ul>
  <button id="more">More results</button>
</div>
<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&libraries=places&callback=initMap" async defer></script>

CSS

/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */
#map {
  height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
#right-panel {
  font-family: 'Roboto','sans-serif';
  line-height: 30px;
  padding-left: 10px;
}

#right-panel select, #right-panel input {
  font-size: 15px;
}

#right-panel select {
  width: 100%;
}

#right-panel i {
  font-size: 12px;
}
#right-panel {
  font-family: Arial, Helvetica, sans-serif;
  position: absolute;
  right: 5px;
  top: 60%;
  margin-top: -195px;
  height: 330px;
  width: 200px;
  padding: 5px;
  z-index: 5;
  border: 1px solid #999;
  background: #fff;
}
h2 {
  font-size: 22px;
  margin: 0 0 5px 0;
}
ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
  height: 271px;
  width: 200px;
  overflow-y: scroll;
}
li {
  background-color: #f1f1f1;
  padding: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
li:nth-child(odd) {
  background-color: #fcfcfc;
}
#more {
  width: 100%;
  margin: 5px 0 0 0;
}

JavaScript

var waypoints = [];
var directionsService;
var directionsRenderer;


function plotWaypoints() {
  var waypts = [];
  for (var i = 0; i < waypoints.length; i++) {
    waypts.push({
      location: waypoints[i].geometry.location,
      stopover: true
    });
  }

  directionsService.route({
    origin: home,
    destination: home,
    waypoints: waypts,
    optimizeWaypoints: true,
    travelMode: 'WALKING'
  }, function(response, status) {
    if (status === 'OK') {
      directionsRenderer.setDirections(response);
      console.log(response);
      var route = response.routes[0];
      var overallDistance = 0;
      // For each route, log some information.
      for (var i = 0; i < route.legs.length; i++) {
        console.log(route.legs[i].distance.text);
        overallDistance += route.legs[i].distance.value;
      }
      console.log("Overall distance in meters: " + overallDistance);
    } else {
      console.log('Directions request failed due to ' + status);
      setTimeout(function(){ 
         	  plotWaypoints();
         }, 5000);
    }
  });
}

function loadWaypoints() {
	dataFromLocalStorage = window.localStorage.getItem('waypoints');
  if(dataFromLocalStorage)
		waypoints = JSON.parse(dataFromLocalStorage);
}