473,287 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Google map routes not showing

Hello! Why can't I get the directions? I'm a beginner and I have no clue where the problem is.

When I open it in the live browser I can see the map but no option to choose routes.



Expand|Select|Wrap|Line Numbers
  1.     <!DOCTYPE html>
  2.     <html>
  3.     <head>
  4.     <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  5.     <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  6.     <style type="text/css">
  7.       html { height: 100% }
  8.       body { height: 100%; margin: 0px; padding: 0px }
  9.       #map_canvas { height: 100%; width: 70%; float: left }
  10.       #directionsPanel { height: 100%; width: 30%; float: right }
  11.     </style>
  12.     <title>Google Maps JavaScript API v3 Example: Map Simple</title>
  13.     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  14.     <script type="text/javascript">
  15.  
  16.       var map;
  17.  
  18.       function initialize() {
  19.  
  20.         var mapContainer = document.getElementById("map_canvas");
  21.  
  22.         var myLatlng = new google.maps.LatLng(61.96059634727177, 9.485308435018732);
  23.         var myOptions = {
  24.           zoom: 5,
  25.           center: myLatlng,
  26.           mapTypeId: google.maps.MapTypeId.ROADMAP
  27.         }
  28.  
  29.         map = new google.maps.Map(mapContainer, myOptions);
  30.       }
  31.     </script>
  32.     </head>
  33.     <body onload="initialize()">
  34.       <div id="map_canvas"></div>
  35.       <div id="directionsPanel"></div>
  36.       <div id="floating-panel">
  37.       <b>Start</b>
  38.       <select id="start:">
  39.         <option value="Oslo, Norway">Oslo</option>
  40.         <option value="Drammen, Norway">Drammen</option>
  41.         <option value="Jevnaker, Norway">Jevnaker</option>
  42.     </select>
  43.     <b>End</b>
  44.     <select id="End:">
  45.       <option value="Oslo, Norway">Oslo</option>
  46.       <option value="Drammen, Norway">Drammen</option>
  47.       <option value="Jevnaker, Norway">Jevnaker</option>
  48.  
  49.  
  50.     </select>
  51.     </div>
  52.     <div id="map"></div>
  53.     <script>
  54.     function initMap() {
  55.       var directionsService = new google.maps.directionsService();
  56.       var directionsDisplay = new google.maps.DirectionsRenderer();
  57.       var map = new google.maps.Map(document.getElementById("Map"), {
  58.         zoom: 7,
  59.  
  60.       });
  61.       directionsDisplay.setMap(map);
  62.       directionsDisplay.setPanel(document.getElementById("directionsPanel"));
  63.  
  64.       var onChangeHandler = function() {
  65.         calculateAndDisplayRoute(directionsService, directionsDisplay);
  66.  
  67.     };
  68.     document.getElementById('Start').addEventListener('change', onChangeHandler);
  69.     document.getElementById('End').addEventListener('change', onChangeHandler);
  70.  
  71.     }
  72.  
  73.     function calcRoute() {
  74.       var start = document.getElementById("start").value;
  75.       var end = document.getElementById("emd").value;
  76.       var request = {
  77.         origin:start,
  78.         destination:end,
  79.         travelMode: google.maps.DirectionsTravelMode.DRIVING
  80.       };
  81.       directionsService.route(request, function(response, status) {
  82.         if (status == google.maps.DirectionsStatus.OK) {
  83.           directionsDisplay.setDirections(response);
  84.         }else {
  85.           alert("Directions failed:" + status);
  86.  
  87.         }
  88.  
  89.         });
  90.     }
  91.  
  92.  
  93.     </script>
  94.  
  95.     <script async defer>
  96.     src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCFIr-BLZtLsDVpj7FPXF0NaCnmgoNUmVE"
  97.     </script>
  98.     </body>
  99.  
  100.     </html>
  101.  
Jul 26 '21 #1
2 4352
dev7060
626 Expert 512MB
Hello! Why can't I get the directions? I'm a beginner and I have no clue where the problem is.
I see errors in the code. Syntax error in lines 95, 96. Typo in line 75. Use the browser developer tools to debug the code. Also, make sure the API key is valid.

When I open it in the live browser I can see the map but no option to choose routes.
Did you try scrolling down?
Jul 29 '21 #2
luckybansko
1 Bit
accidently commented sorry~!
Aug 11 '21 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Mario | last post by:
Hello everybody, I am looking for a good script to work a searchprogram for Google .... How can tel me? Not with a logo from google THnx -- -------"""------- ---()--- °?----(_)-----?° |...
8
by: Daniele | last post by:
Hi there is a way to put in a struct of vectors all the possibles routes in a graph from s to d? Hi thought Dijkstra but I don't know how can i do. Thanks Dax
4
by: mitymouse | last post by:
I am fairly familiar with scripting dos commands and that's about it. I remember some syntax and whatnot from a few programming classes I've taken but I don't remember any of the modules or functions...
7
by: underground | last post by:
I have a problem that I've spent countless hours on and I'm more than certain this is a obviuos issue to an expert but I am still learning. I have a paging script that I have modified to display a...
1
by: shapper | last post by:
Hi, I was checking the new ASP.NET MVC Preview 4 features and I found the following: var dataTokens = new RouteValueDictionary(); dataTokens.Add("namespaces", new HashSet<string>( new string...
4
by: ursular | last post by:
Hi all, I'm new to JavaScript and Google Maps API. I got some problems but I cannot find out the reason. Hope someone can help me. What I tried to do: I'm trying to develop an application in...
0
by: Nicodemas | last post by:
I have a web site on a web hosting company's Windows server. The same server also handles my "@nicodemas.com" email and DNS. I have changed my MX records away from their service and use Google...
0
by: spt1956 | last post by:
/system/service.php My Google analytic is showing a good percentage of visits from random sites that i am not familiar with. the referral is PRweb. If the are the referral source why are all these...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.