JSFiddle - React, Tailwind, and code Playground
by gurkavcu
HTML
<script src="http://maps.google.com/maps/api/js?sensor=false&.js"></script>
<div id="map_canvas">map</div>
CSS
#map_canvas {width:400px; height:400px; background:#ccc;}
JavaScript
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
directionsDisplay = new google.maps.DirectionsRenderer();
var point1 = new google.maps.LatLng(36.2556200857637, 28.16609663391114);
var point2 = new google.maps.LatLng(36.1683287597509, 28.09588713073731);
var myOptions = {
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: point1
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
var marker1 = new google.maps.Marker({
position: point1,
map: map,
title: "Point 1 - start"
});
var marker2 = new google.maps.Marker({
position: point2,
map: map,
title: "Point 2 - end"
});
var startpoint = '36.2556200857637, 28.16609663391114';
var endpoint = '36.1683287597509, 28.09588713073731';
var request = {
origin: startpoint,
destination: endpoint,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});