Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8195771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:15:04+00:00 2026-06-07T05:15:04+00:00

I am new to the Google Maps API and so far I have run

  • 0

I am new to the Google Maps API and so far I have run into many issues.

I am trying to map waypoints from latlng coords determined by an array of checkboxes.

Here is my js file in full:

var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;


var waypts = [];
var start = new google.maps.LatLng(41.850033, -87.6500523);
var end = new google.maps.LatLng(40.850033, -87.6500523);

function initialize() 
{
    directionsDisplay = new google.maps.DirectionsRenderer();
    var myOptions = {
        zoom: 6,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: new google.maps.LatLng(41.850033, -87.6500523)
    }

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    directionsDisplay.setMap(map);

}

function calcRoute()
{
    var checkboxArray = document.getElementsByName("waypoints[]");


    for (var i = 0; i < checkboxArray.length; i++) 
    {
        if (checkboxArray[i].checked) 
        {
            var lat = parseFloat(checkboxArray[i].attributes["lat"].value);
            var lng = parseFloat(checkboxArray[i].attributes["lng"].value);

            waypts.push({
                location: new google.maps.LatLng(lat, lng),
                stopover: true
            });
        }
    }
}

var request = {
    origin: start, 
    destination: end,
    waypoints: waypts,
    optimizeWaypoints: true,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request, function(response, status) {
    console.log("mapping...");

    if(status == google.maps.DirectionsStatus.NOT_FOUND)
    {
        console.log("Could not one or more of locations");
    }
});

The map shows up and “mappings…” pops in the console when the page loads. When I press the calcRoute submit button nothing happens. I have logged the lat/long and the waypt object so I know they are getting to that point but it seems the route is never recalculated, etc.

I really just need a basic demo on this but the only one I have found is which I have used for almost everything but I get no results:
Google Example Directions Waypoints

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:15:06+00:00Added an answer on June 7, 2026 at 5:15 am

    Currently your script never will show any route, because you are missing the call of directionsDisplay.setDirections() to print the route.

    You also should should put the call of directionsService.route() into the calcRoute-function.

    fixed code:

    <script type="text/javascript">
    var directionDisplay;
    var directionsService = new google.maps.DirectionsService();
    var map;
    
    var start = new google.maps.LatLng(41.850033, -87.6500523);
    var end = new google.maps.LatLng(40.850033, -87.6500523);
    
    function initialize() 
    {
        directionsDisplay = new google.maps.DirectionsRenderer();
        var myOptions = {
            zoom: 12,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: new google.maps.LatLng(41.850033, -87.6500523)
        }
    
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        directionsDisplay.setMap(map);
    
    }
    
    function calcRoute()
    {
        var checkboxArray = document.getElementsByName("waypoints[]");
        var waypoints=[];
    
        for (var i = 0; i < checkboxArray.length; i++) 
        {
            if (checkboxArray[i].checked) 
            {
                var lat = parseFloat(checkboxArray[i].attributes["lat"].value);
                var lng = parseFloat(checkboxArray[i].attributes["lng"].value);
    
                waypts.push({
                    location: new google.maps.LatLng(lat, lng),
                    stopover: true
                });
            }
        }
    
    
    var request = {
        origin: start, 
        destination: end,
        waypoints: waypts,
        optimizeWaypoints: true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    
    directionsService.route(request, function(response, status) {
        if(status == google.maps.DirectionsStatus.OK)
        {
            //print the route
            directionsDisplay.setDirections(response);
        }
        else
        {
          console.log('something went wrong',status);
        }
    
    });
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a map using the new(ish) v3 of the Google Maps API
var center = new google.maps.LatLng(18.133333, 21.566667); var map = new google.maps.Map(document.getElementById('map'), {zoom: 11,center: center,mapTypeId:
GOOGLE MAPS API V3 is what i'm trying to use. I have all the
I'm trying to create map (using the Google Maps JavaScript API V3 ) which
I am new with google maps api. I took some sample from the manual
I'm playing with the Google Maps API (v3) and I've run into an issue
I am try the Google Maps API and run into a little problem. Look
I'm new to JavaScript and the Google Maps API v3. I'm trying the Developer's
I am trying to use google maps API V3 to draw a line from
I am using Google Maps API v3 , and have several map markers that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.