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 8833481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:47:21+00:00 2026-06-14T08:47:21+00:00

This is my code: function trainRoute(startPoint, endPoint) { var polyline = new google.maps.Polyline({ strokeColor:

  • 0

This is my code:

function trainRoute(startPoint, endPoint) {
    var polyline = new google.maps.Polyline({ strokeColor: '#af1a1a', strokeWeight: 2 });
    var directionsService = new google.maps.DirectionsService();
    var directionsDisplay = new google.maps.DirectionsRenderer({ polylineOptions: polyline, suppressMarkers: true });
    directionsDisplay.setMap(map);

    var request = {
        origin: startPoint,
        destination: endPoint,
        travelMode: google.maps.DirectionsTravelMode.TRANSIT 
    };

    directionsService.route(request, function (response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);

            var legs = response.routes[0].legs;
            for (i = 0; i < legs.length; i++) {
                var steps = legs[i].steps;
                for (j = 0; j < steps.length; j++) {
                    var nextSegment = steps[j].path;
                    for (k = 0; k < nextSegment.length; k++) {
                        polyline.getPath().push(nextSegment[k]);
                        //bounds.extend(nextSegment[k]);
                    }
                }
            }
        }
    });
}

Using travelMode: google.maps.DirectionsTravelMode.WALKING I see the line, but it is not what I’m looking for. I think I need .TRANSIT with some more options, like VehicleType.RAIL.

I don’t know how to do it! I’ve tried on searching on Google, but couldn’t find anything!


I think this is the right way to do this :

var request = {
    origin: puntoPartenza,
    destination: puntoArrivo,
    travelMode: google.maps.TravelMode.TRANSIT
};

directionsService.route(request, function (response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);

        var legs = response.routes[0].legs;
        for (i = 0; i < legs.length; i++) {
            var steps = legs[i].steps;
            for (j = 0; j < steps.length; j++) {
                var transitMode = steps[j].travel_mode;

                if (transitMode == "TRANSIT") {
                    var vehicle = steps[j].transit.line.vehicle.type;
                    if (vehicle == "HEAVY_RAIL") {
                        var nextSegment = steps[j].path;

                        for (k = 0; k < nextSegment.length; k++) {
                            polyline.getPath().push(nextSegment[k]);
                        }                            
                    }
                }


            }
        }
    }
});

but :

1) why it draw only a part of route?

2) on the returned JSON object of DirectionsStatus, there are also info about walking and/or TRANSIT. So what’s the meaning of travelMode: google.maps.DirectionsTravelMode.TRANSIT ?!?!?

but I get TypeError: google.maps.TransitVehicle is undefined

  • 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-14T08:47:23+00:00Added an answer on June 14, 2026 at 8:47 am

    You can’t just make up syntax and expect it to work Transit VehicleType does include RAIL, but TransitVehicle, doesn’t have a vehicle property.

    There is no property vehicle in Transit vehicle. Look at the “type” property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code function test(){}; test.prototype.testMethod = function(){return 1;} var t = new
i have this code function imagenesIn(errU,errores) { if(errU) throw errU; var directorios=new Array(); var
I have this code: function render_message(id) { var xmlHttp; xmlHttp=new XMLHttpRequest(); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4)
If I run this Code: function sendRequest() { var req = new XMLHttpRequest(); req.open(GET,
I want this code: function renderTemplate(temp,content){ for (var i in temp){ replace = new
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I got this code: function zeroPad(num, places) { var zero = places - num.toString().length
Hello I get a weird error in this code: function validateForm(aform) { var s=;
I have this code: _trackit: function(){ for(var key in this.items.sublinks){ switch(key){ case 'shoes': for(var
With this code: function setupRow(event, ui) { var textbox, // how do i get

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.