none
Invalid Trip Start and End Times in Directions Results? RRS feed

  • Question

  • Hello,

    I am seeing incorrect trip start times in results of transit directions requests.

    For example, 

    From

    San Francisco Transbay Terminal, CA

    To

    Oxford St, Berkeley, CA 94709

    Time

    Aug 12, 2018 3:45 pm 

    With timeType: 2

    Produces correct durations but start and end times appear to have incorrect hour offsets.  The first selection in results is 11:01PM - 11:59PM

    The regular javascript Date includes timezone offsets, so I assume that would suffice without additional instruction in the documentation. 

    As of now users are hit with nonsense.  Any idea what is going on? 


    Sunday, August 12, 2018 10:48 PM

All replies

  • Can you give me the details of the exact call, without your key of course!  I am not reproducing the issue here so there is obviously something I am missing.
    Monday, August 13, 2018 3:53 PM
    Owner
  • I looked into this some more.

    I am not seeing it on the main Bing Directions website, but I am still seeing it with the Map Control v8.

    It's a standard request just adding two waypoints and setting request options with no custom renderer.

    Here is the JSON of the request options object:

    {routeDraggable: true, routeMode: 2, routeOptimization: "shortestTime", time: Mon Aug 13 2018 12:15:00 GMT-0700 (Pacific Daylight Time), timeType: 2, …}

    The only other source of error I can imagine is with the .addWaypoint but that is clearly correct in the results. 

    Any ideas on how to fix it? 

    Here some lead up code:

                            

    mps = Microsoft.Maps;
    mm = mps.Directions;

    if(pl_dir_bing_manager){
    try{//this throws error
    pl_dir_bing_manager.clearAll();
    pl_dir_bing_manager.clearDisplay();
    }catch(e){}
    }
    pl_dir_bing_manager = null;
    pl_dir_bing_manager = new mm.DirectionsManager(pl_bing_map);
    if(!pl_dir_bing_manager){
    throw 'Microsoft is not defined.';
    }
    mps.Events.addHandler(pl_dir_bing_manager,'directionsError',pl_dir_bing_error);
    mps.Events.addHandler(pl_dir_bing_manager,'directionsUpdated',pl_dir_bing_complete);
    pl_dir_bing_manager.rs_done = 0;


    var swp, ewp, latLongArray;
    if(!fLL(pl_dir_reqo.sll)){
    swp = new mm.Waypoint({address:pl_dir_reqo.s});
    }else{
    latLongArray = pl_dir_reqo.sll.split(',');
    var sLoc = new mps.Location(latLongArray[0],latLongArray[1]);
    swp = new mm.Waypoint({location:sLoc});
    }
    if(!fLL(pl_dir_reqo.ell)){
    ewp = new mm.Waypoint({address:pl_dir_reqo.e});
    }else{
    latLongArray = pl_dir_reqo.ell.split(',');
    var eLoc = new mps.Location(latLongArray[0],latLongArray[1]);
    ewp = new mm.Waypoint({location:eLoc});
    }
    pl_dir_bing_manager.addWaypoint(swp);
    pl_dir_bing_manager.addWaypoint(ewp);

    var ra = '';
    n = pl_dir_reqo.opt.split(',');
    if(n[0]!='no_pref'){
    ra = n[0]+'Highways';
    }

    pl_dir_bing_manager.setRenderOptions({ itineraryContainer: fID(p+'_status') });

    var rp = 'shortestTime', p2 = 'pl_dir_optimize_bing_';
    if(fGA(p2+'distance','data-selected') == 1){
    rp = 'shortestDistance';
    }else if(fGA(p2+'timewithtraffic','data-selected') == 1){
    rp = 'timeWithTraffic';
    }else if(fGA(p2+'timeavoidclosure','data-selected') == 1){
    rp = 'timeAvoidClosure';
    }
    pl_dir_reqo.rp = rp;//route optimiation

    //arrival/departure
    pl_dir_reqo.dt = fID('pl_cal_input').value;
    pl_dir_reqo.ad = fID('pl_time_depart').checked;

    //time types
    var dt = new Date(), tt = (pl_dir_reqo.ad)?mm.TimeTypes.departure:mm.TimeTypes.arrival;
    if(fGA('pl_dir_timetype_bing_first','data-selected') == 1){
    tt = mm.TimeTypes.firstAvailable;
    }else{
    if(fGA('pl_dir_timetype_bing_last','data-selected') == 1){
    tt = mm.TimeTypes.lastAvailable;
    }
    n = Date.parse(pl_dir_reqo.dt);
    if( isNaN(n) ){//default to now if invalid
    dt = new Date();
    }else{
    dt = new Date(pl_dir_reqo.dt);
    }
    }
    //V8 - transitOptions removed; use DirectionsRequestOptions
    var req_opts={//not yet supported outside Japan: minimizeMoney, minimizeTransfers, minimizeWalking
    routeDraggable:true,
    routeMode:mm.RouteMode.transit,
    routeOptimization:rp,
    time:dt,
    timeType:tt,
    maxRoutes:4
    };
    if(ra){
    req_opts.routeAvoidance = ra;
    }
    //units
    n = fGSS('units');
    if(!n){
    n = fGLS('me_units');
    if(n){
    fSSS('units',n);
    }
    }
    if(n){
    req_opts.distanceUnit = (n=='mi')?mm.DistanceUnit.miles:mm.DistanceUnit.km;
    }

    //console.log(req_opts);

    pl_dir_bing_manager.setRequestOptions(req_opts);
    pl_dir_bing_manager.setRenderOptions({
    itineraryContainer: fID('pl_dir_status'),
    autoUpdateMapView:true,
    displayManeuverIcons:true,
    displayRouteSelector:true,
    displayStepWarnings:true,
                        displayWalkingWarning:true,
    showInputPanel:false,
    walkingPolylineOptions:{
    strokeDashArray:"2 0",
    strokeColor:new mps.Color(0.8,51,119,205),
    strokeThickness:6,
    visible:true
    }

    });

    pl_dir_bing_manager.calculateDirections();



    Monday, August 13, 2018 7:28 PM
  • Do you have just the final call string so I can pull the results?  My current thinking is this may be due to how the date is being passed but that is just a wild guess.  I won't know until I see the actual string you built for the request.
    Monday, August 20, 2018 6:22 PM
    Owner
  • There is no final call string.  Waypoints are added, request options are set and cacluateDirections is called.

    To reproduce, you should be able to just set the request options as below:

    {routeDraggable: true, routeMode: 2, routeOptimization: "shortestTime", time: Mon Aug 13 2018 12:15:00 GMT-0700 (Pacific Daylight Time), timeType: 2, …}

    Add the waypoints for the addresses and call calculateDirections. 

    The time attribute of the options object is just a Javascript Date as per the documentation. 

    You can simply add in a new date:

    var dt = new Date(); 

    request_opt.time = dt; 

    ....

    I did notice results are correct if the timeType is firstAvailable and incorrect if timeType is arrival or departure. 

    Also, routes are almost never found if timeType is lastAvailable with a date some time in the future.  

    I white box tested values before the call to calculateDirections and values are valid and use API enums explicitly. 

    Errors appear associated with forking based on timeType.

    Tuesday, August 21, 2018 2:13 AM