Jquery City Dropdown To Google Map Show Route Example

Admin   HTML5 - CSS   185  2021-03-12 22:50:06

Hi Guys,

Today,I will learn you how to create dropdown selected City show google map route. we will show example jquery city dropdown to google map show route.you can easy create jquery city dropdown to google map show route.

Here, I will give you full example for simply display City Dropdown To Google Map Show Route using jquery as bellow.





<title>Jquery City Dropdown To Google Map Show Route Example</title>

<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&&callback=initMap&libraries=&v=weekly" defer></script>

<style type="text/css">

/* Optional: Makes the sample page fill the window. */


body {

height: 100%;

margin: 0;

padding: 0;


#floating-panel {

position: absolute;

top: 10px;

left: 25%;

z-index: 5;

background-color: #fff;

padding: 5px;

border: 1px solid #999;

text-align: center;

font-family: "Roboto", "sans-serif";

line-height: 30px;

padding-left: 10px;



width: 100%;

height: 500px;

margin-top: 100px;





<div id="floating-panel">

<b>Start: </b>

<select id="start">

<option value="rajkot">Rajkot</option>

<option value="nashik">Nashik</option>

<option value="indore">Indore</option>

<option value="vadodara">Vadodara</option>


<b>End: </b>

<select id="end">

<option value="rajkot">Rajkot</option>

<option value="nashik">Nashik</option>

<option value="indore">Indore</option>

<option value="vadodara">Vadodara</option>



<div id="map"></div>



function initMap() {

const directionsService = new google.maps.DirectionsService();

const directionsRenderer = new google.maps.DirectionsRenderer();

const map = new google.maps.Map(document.getElementById("map"), {

zoom: 7,

center: { lat: 20.00, lng: 77.00 },



const onChangeHandler = function () {

calculateAndDisplayRoute(directionsService, directionsRenderer);




.addEventListener("change", onChangeHandler);



.addEventListener("change", onChangeHandler);


function calculateAndDisplayRoute(directionsService, directionsRenderer) {



origin: {

query: document.getElementById("start").value,


destination: {

query: document.getElementById("end").value,


travelMode: google.maps.TravelMode.DRIVING,


(response, status) => {

if (status === "OK") {


} else {

window.alert("Directions request failed due to " + status);







It will help you....