Troubleshooting my code: The mystery of why Google Map directions won't cooperate!

Can anyone help me figure out why my code for drawing a path between multiple points on a map isn't working? I've tried the code below, but it doesn't draw any paths. What could be causing this issue and how can I solve it?


var myTrip = [], waypts=[];    
myTrip.push(new google.maps.LatLng(32.6384014, 51.65132887000004));
waypts.push({
    location: new google.maps.LatLng(32.6384014, 51.65132887000004),
    stopover: true
});

myTrip.push(new google.maps.LatLng(32.63727025, 51.65345639999998));
waypts.push({
    location: new google.maps.LatLng(32.63727025, 51.65345639999998),
    stopover: true
});

myTrip.push(new google.maps.LatLng(32.6367726, 51.65345639999998));
waypts.push({
    location: new google.maps.LatLng(32.6367726, 51.65677270000003),
    stopover: true
});                       

var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer(
{
    suppressMarkers: true,
    suppressInfoWindows: true
});
directionsDisplay.setMap(map);
var request = {
    origin: myTrip[0],
    destination: myTrip[myTrip.length - 1],
    waypoints: waypts,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
    if (status == google.maps.DirectionsStatus.OK) {

        directionsDisplay.setDirections(response);
    }
});

If you want to check out my code in action, here is the link to my jsfiddle: jsfiddle geomap

Answer №1

My issue stems from the number of waypoints, as mentioned in the Google Maps reference: reference for Google Map developers

The maximum number of allowed waypoints is 8, including the origin and destination points. Customers using Google Maps API for Work are permitted up to 23 waypoints, along with the origin and destination. Please note that waypoints cannot be used for transit directions.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

how can you activate a modal without relying on bootstrap?

Could anyone suggest a more efficient way to create a pop-up modal triggered by a button click without relying on bootstrap? I've attempted different methods but haven't achieved the desired result. Here's a sample plunker for reference. Any ...

Utilize the power of REACT JS to transform a specific segment within a paragraph into a hyperlink. Take advantage of the click event on that hyperlink to execute an API request prior to

In React JSX, I'm encountering an issue trying to dynamically convert a section of text into an anchor tag. Additionally, upon clicking the anchor tag, I need to make an API call before redirecting it to the requested page. Despite my attempts, I have ...

Tips for patiently waiting for a series of asynchronous calls to successfully complete

I have a scenario where I am dealing with multiple asynchronous calls that are dependent on each other's success. For example: function1 = () => { /*Some required Logic*/ return fetch("myurl") .then((json) => { functi ...

fetch information using ajax and jquery

I'm facing an issue with my ajax request on my website. I'm trying to dynamically fetch pages from a database using jquery and ajax. However, I'm not getting any response, and I'm unsure whether the problem lies in my php code or my j ...

When attempting to retrieve a data object using a Vuex action, I encounter an "Uncaught (in promise) TypeError" when trying to access the data within the object

Recently, I've been diving into Vuex and its actions for fetching data. While everything seems to be working smoothly - accessing the films object, selecting films from it - I encounter an error when trying to access specific data within a film. Vuex ...

What is the best way to fill in references that are nested within an array object using mongoose?

How do I go about populating the product fields within the cart array provided below? { "_id": "5bbd1c6e2c48f512fcd733b4", "cart": [ { "count": 1, "_id": "5bbd30ed9417363f345b15fc", "product": "5ba93a6d ...

Leveraging jsonp with nodejs and original ajax

I wanted to understand how jsonp works, so I decided to create a demo using nodejs without jQuery. However, I encountered some issues with my code. Here is what I tried: views/index.jade doctype html html head title Demo of jsonp body #res ...

Discover the significance of a data attribute's value for effective comparisons

I have a loop that generates random numbers and positions to create 4 answer choices for users. Now, I am trying to determine the value of the clicked button and compare it to the position of the correct answer. However, whenever I try to do this, it retu ...

Developing web components using angular.js while ensuring compatibility with IE11

I have an angular.js application where I need to initialize a web component. Everything runs smoothly on different browsers, however IE11 seems to have problems with document.importNode The angular.js onInit function is as follows: vm.$onIni ...

Unexpected Behavior Arises from Axios Get API Request

Below is a functional example in my CodePen showing what should be happening. Everything is working as intended with hard coded data. CodePen: https://codepen.io/anon/pen/XxNORW?editors=0001 Hard coded data: info:[ { "id": 1, "title": "Title one ...

Avoiding mocking a specific module with jest forever

Our codebase heavily relies on underscore in various parts, and I prefer to avoid mocking it. I'm aware that I can use jest.unmock('underscore'); in each test that utilizes underscore. Is there a method to unmock underscore across all tests ...

What is the most effective method for refreshing a control following an Ajax request?

I am currently working on a website that sends an Ajax request to save data to a database. I would like to update the webpage to show the user that their changes have been successfully submitted. I have brainstormed three possible solutions: Immediately ...

Sharing specific props with deeply nested components in React

I am experimenting with configuring props for children components. In this example, I am testing a function to target any child, whether nested or not, with the prop swipeMe. It works perfectly when the render function contains only a single child, like ...

"Although the ajax request was successful, the post data did not transfer to the other

i am working with a simple piece of code: var addUser = "simply"; $.ajax({ type: 'POST', url: 'userControl.php', data: {addUser: addUser}, success: function(response){ alert("success"); } }); on the page use ...

Script for tracking user activity on Facebook and Google platforms

I currently have Google tracking conversion set up, but now I also need to implement Facebook pixel tracking. My existing Google Head Script code is as follows: <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||fu ...

I am unable to send back my JSON object

I seem to be having trouble returning a JSON object as all I get is an undefined variable. The code below is supposed to fetch a JSON element from an API. It appears to work within the success: function, but when attempting to use that data elsewhere, it ...

Styling the "Browse" button for different web browsers

Here is the code snippet I am working with: HTML: <form> <input id = "file" type="file" /> <div id="custom_button">custom button</div> </form> Jquery: $("#custom_button").on("click", function () { $("#file"). ...

What's the Catch with Vue's Named Slots?

When working with Named Slots in Vue (using the older, more verbose API for component slots), if there is a reusable component with a template structured like this: <template> <div v-for="field in formFields"> <slot name="`${field.key}_P ...

What is the best way to retrieve EXIF data following the AJAX loading of images?

Currently, I am developing a swipe-able wine image viewer for NapaWapa.com and it's functioning quite smoothly: The challenge I'm facing is related to using a jquery plugin to extract the exif data from the images in the gallery. Unfortunately, ...

Two arrays with varying sizes, utilizing one array repeatedly within a loop once its maximum index is reached

I have two arrays set up, and my goal is to iterate through the larger array and assign a property to it using randomly selected IDs from the smaller array. //The actual length of the users array is 140 const users = [ { name: "John Roberts", ui ...