ThunD3eR
ThunD3eR

Reputation: 3456

How to get a route that goes by ferry and by automobile? GMAPS

I am currently updating gmaps V2 to Version 3. So far most of it is going pretty good but im stuck on this.

I Need a route that will travel via ferry but i have a travelmode set to driving. I have one waypoint that the route always uses but since it ignores the sea it goes to my waypoint and goes back a bit to use a bridge to travel over the water.

To clarify: User specifies a city to travel from----> goes via standard waypoint----> uses ferry to travel over the sea---> conntinnues driving to destination.

My problem is simply that gmaps ignores the sea and finds routs where there are bridges and what not.

Code:

<asp:PlaceHolder ID="International" runat="server" visible="false">
                /*Ferry is required*/
                viaAddress = document.getElementById('viaAddress').value;
                var noOfPoints = 4;
                var waypoints = new Array(noOfPoints); 
                waypoints[0] = fromAddress;
                if (viaAddress == 'Rostock')
                    waypoints[<%=GetVia(1) %>] = '55.366936,13.151429'; //(Trelleborg - Rostock) 55.372387,13.149916
                else
                    waypoints[<%=GetVia(1) %>] = '55.368844,13.151515';
                waypoints[<%=GetVia(2) %>] = viaAddress;
                waypoints[3] = '<%=GetToAddress() %>';
            </asp:PlaceHolder>

            directionsDisplay = new google.maps.DirectionsRenderer();
            directionsDisplay.setMap(mapdir);

            gdir.route({
            origin: waypoints[0],
            destination: waypoints[3],
            waypoints: [{
            location: waypoints[1]
            }
            ],
            provideRouteAlternatives: false,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
          }, function(result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
              directionsDisplay.setDirections(result);
            }
          });
        }

If any1 asks: This is not in a scriptfile, I "inherited" this tasks from a seasoned developer that did it like this several years ago, don't ask me why.

I have been searching the net on how to do this but I have not come up with anything, been reading the following with no luck:

https://developers.google.com/maps/documentation/javascript/directions?hl=sv https://developers.google.com/maps/documentation/javascript/reference#DirectionsWaypoint

If anyone out there has the answer im very thankful and would appreciate it if i could get some links so that i can read up on this.

Thank you!

Upvotes: 0

Views: 2664

Answers (2)

geocodezip
geocodezip

Reputation: 161334

From the changelog

3.16 24 February 2014

Added: Support for ferries in Distance Matrix and Directions services.

Upvotes: 1

ThunD3eR
ThunD3eR

Reputation: 3456

After a long while i finaly found the soloution! check here:

http://www.codeproject.com/Answers/579741/How-to-get-a-route-that-travels-over-water.aspx#answer2

Upvotes: 0

Related Questions