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
// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
var map;
var directionsService;
var directionsRenderer;
var directionsRenderer1;
var directionsRenderer2;
var directionsRenderer3;
var service;
var waypoints = [];
var home;
function initMap() {
loadWaypoints();
directionsService = new google.maps.DirectionsService();
directionsRenderer = new google.maps.DirectionsRenderer();
directionsRenderer1 = new google.maps.DirectionsRenderer();
directionsRenderer2 = new google.maps.DirectionsRenderer();
directionsRenderer3 = new google.maps.DirectionsRenderer();
directionsRenderer4 = new google.maps.DirectionsRenderer();
// Create the map.
home = {lat: 35.7124235, lng: 139.7851794};
map = new google.maps.Map(document.getElementById('map'), {
center: home,
zoom: 18
});
directionsRenderer.setMap(map);
directionsRenderer1.setMap(map);
directionsRenderer2.setMap(map);
directionsRenderer3.setMap(map);
directionsRenderer4.setMap(map);
// Create the places service.
service = new google.maps.places.PlacesService(map);
//figure out the beginning
var begin = new google.maps.LatLng(35.7124235, 139.7851794);
if(waypoints.length>0) {
begin = waypoints[waypoints.length-1].geometry.location;
console.log("Beginning set to:");
console.log(begin);
}
// Perform a nearby search.
getNextStop(begin, waypoints.length);
}
function getNextStop(start, counter) {
plotWaypoints(0);
if(counter < 75) {
service.nearbySearch(
{location: start, radius: 500, type: ['convenience_store']},
function(results, status, pagination) {
if (status !== 'OK') return;
calcRoutes(start, results, [], 0, counter);
});
} else {
plotWaypoints(0);
}
}
function calcRoutes(origin, places, distances, i, counter) {
var...