4

I am currently developing a map where the shortest route between two points is shown (using different transports). I have noticed that sometimes, roads that are for example closed in the winter, are not taken into consideration.

I have found that I can ignore highways, tolls and ferries using the directionsservice (code below), but I can't for the life of me figure out how/if I can ignore seasonal restrictions. Any help is greatly appreciated.

var request = {
    origin: _marker_from,
    destination: _marker_to,    
    travelMode: _mode,
    avoidFerries: false,
    avoidTolls: false,
    //avoidTimedConditions: true <-- I would need something like this
};

_service.route(request, function (response, status) {
    //More code here, not relevant for this question
}
geocodezip
  • 158,664
  • 13
  • 220
  • 245
Michiel Standaert
  • 4,096
  • 7
  • 27
  • 49
  • 2
    If you vote to close and downvote me, at least have the decency to tell me what is wrong with my question :) – Michiel Standaert Apr 28 '18 at 21:22
  • 1
    Good question. I’m interested if this is possible. – Cory Kleiser Apr 28 '18 at 21:25
  • What does this have to do with jQuery? – geocodezip Apr 28 '18 at 23:49
  • 1
    Related question: [Google Maps v3 DistanceMatrix/Directions ignore avoidTolls:false](https://stackoverflow.com/questions/19819586/google-maps-v3-distancematrix-directions-ignore-avoidtollsfalse) – geocodezip Apr 29 '18 at 00:17
  • 1
    I believe there is no easy way to ignore temporary closures. You can try setting departure time to the timestamp when the road should be open as a workaround. – xomena Apr 29 '18 at 10:40
  • @geocodezip: Just providing all the info I can give :) I just tried the provideRouteAlternatives:true-approach suggested in your post, but it doesn't work. – Michiel Standaert Apr 30 '18 at 21:46
  • @xomena, setting departure times is only for premium business clients, as far as I can tell, and I am unfortunately not one of those. Plus, I want to make the website as dynamic as possible, because certain roads are closed at different times, But I think I'll have to accept that what I want is not possible. – Michiel Standaert Apr 30 '18 at 21:48
  • @Michiel Standaert Departure time is available in Standard plan as well if you use a valid API key. According to the documentation `This option is only available if the **request contains a valid API key**, or a valid Google Maps APIs Premium Plan client ID and signature. The departure_time must be set to the current time or some time in the future. It cannot be in the past.` https://developers.google.com/maps/documentation/directions/intro#DirectionsRequests – xomena Apr 30 '18 at 22:10

1 Answers1

0

You can use the departureTime in the drivingOptions of the directions request. Setting it to some point in time next summer should do the trick:

let now = new Date();

var request = {
    origin: _marker_from,
    destination: _marker_to,    
    travelMode: _mode,
    avoidFerries: false,
    avoidTolls: false,
    drivingOptions: {
        departureTime: new Date(now.getFullYear() + 1 + '/07/30'),
    }
};
Tobias Gassmann
  • 11,399
  • 15
  • 58
  • 92