Google maps api 3 多次错误中途停留会导致方向搜索失败

Google maps api 3 多次错误中途停留会导致方向搜索失败,google-maps-api-3,Google Maps Api 3,我在一组Lat/Lng坐标上运行了两次查询,并且在有多个中途停留时得到了失败的结果 在单个航路点上设置stopover:false时,搜索将正确返回 当在多个航路点上设置stopover:false时,搜索结果为零 当在任意数量的航路点上设置stopover:true时,这些航路点似乎从方向距离中消失 // Query 1 uses the format: Pickup - Taxi rank coods - Destination: query = 'from: 50.899083,0.04

我在一组Lat/Lng坐标上运行了两次查询,并且在有多个中途停留时得到了失败的结果

  • 在单个航路点上设置stopover:false时,搜索将正确返回
  • 当在多个航路点上设置stopover:false时,搜索结果为零
  • 当在任意数量的航路点上设置stopover:true时,这些航路点似乎从方向距离中消失

    // Query 1 uses the format: Pickup - Taxi rank coods - Destination:
    query = 'from: 50.899083,0.040018 to: 50.875629,0.017858 to: 50.972639,0.016789';
    
    
    // Query 2 uses the format: Pickup - Waypoint 1 - Waypoint 2 - Destination
    query = 'from: 50.899083,0.040018 to: 50.82988,-0.14095 to: 50.87077,0.01328 to: 50.972639,0.016789';
    
    
    var start = query.split('from: '),
        end = start[1].split(' to: '),
        jLength = end.length,
        routeDistance = [],
        jWaypoints = [],
        request,
        i;
    
    start = end[0];
    // At this point, start = 50.899083,0.040018
    
    if( (jLength - 2) > 0 ) {
        for (i = jLength - 1; i >= 0; i--) {
            if( i != ( jLength - 1 ) && i != 0 ) {
                jWaypoints.push( {
                    location: end[i],
                    stopover: false
                });
            }
        }
    }
    end = end[jLength - 1];
    
    // end = 50.972639,0.016789
    // jWaypoints = [Object { location="50.87077,0.01328", stopover=false}, Object { location="50.82988,-0.14095", stopover=false}];
    
    
    if( jWaypoints.length >= 1 ) {
        request = {
            origin:start,
            destination:end,
            waypoints: jWaypoints,
            optimizeWaypoints: false,
            travelMode: google.maps.TravelMode.DRIVING
        };
    } else {
        request = {
            origin:start,
            destination:end,
            travelMode: google.maps.TravelMode.DRIVING
        };
    }
    
    
    directions.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
            routeDistance.push(response.routes[0].legs[0].distance.value, response.routes[0].legs[0].duration.value);
            passDistance(callback, stopnames, latlons, queries, queryindex, results, routeDistance);
        } else {
            console.log( status );
        }
    });
    
    // Query 1 comes out as: [20560, 1472] -> Correct
    // Query 2 comes out as: ZERO_RESULTS
    
/-编辑-/


结果表明,当中途停留设置为true时,只拾取最终航路点。但这一点仍然不明智。

如果你想使用坐标作为航路点,它必须是一个对象,而不是一个包含两个用逗号分隔的数字的字符串。

问题是在提醒它们之前,距离的最后一次取整。通过遍历所有支腿并对结果求和,返回正确的距离。由此:

 routeDistance.push(response.routes[0].legs[0])
致:


多个航路点,对我来说是正确的和错误的。也许你可以做一把小提琴来展示这个问题。@geocodezip谢谢你的测试。试试这个:。在加载的查询中,第二个航路点靠近终点。在注释掉的查询中,第二个航路点距离我们很远。在两个示例中,它似乎都没有拾取第一个航路点。起点、终点和航路点都不是LatLng对象;航路点不在公路上,如果在航路点设置了标记,就可以看到。不知道我在找什么。警报告诉我什么?在将航路点和开始/结束字符串更新到google.maps.LatLng对象后,同样的问题也发生了。当查询为开始->近航路点->远航路点->目的地时,第69行的结束警报(取自directions.route calculation)返回18863米。当查询为开始->远航路点->近航路点->目的地时,警报返回3449米。我有点困惑,为什么相同的合作伙伴以不同的顺序返回如此大的不同结果。看看coords,我不认为在开始-远-近-端查询时,旅程可能会短得多,而不会完全遗漏远航路点。他们对meSorry@geocodezip说,我对我最初的问题一点也不清楚-我的道歉。应该再清楚一点。为了得到不同的结果,我在函数顶部交换了带注释的查询。现在,我已将其作为查询数组中的第二个元素。查询变量现在包含两个字符串,一个是S->Far->Near->D,第二个是S->Near->Far->D。我刚才提到的不同结果仍在发生,如图所示alerts@trysmudford仅供参考:我通过
stopover:false
将查询更改为
query='from:50.899083,0.040018 to:50.87177,0.01321 to:50.830195,-0.14045 to:50.972639,0.016789'。它只是做了一点改变,这样车就在路上,而不是在路上。
jDistance = 0;

for(i = 0, i >= response.routes[0].legs.length, i++) {
    jDistance += response.routes[0].legs[i];
}

routeDistance.push(jDistance);