473,396 Members | 1,797 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,396 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 4358
dev7060
636 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.