“alternatives = true”无法在Google Direction API中使用

时间:2017-02-21 17:23:47

标签: android google-maps google-maps-direction-api

我正在使用Google的Direction API在源和目标之间绘制一条行车路径。我想显示多个替代路由,所以我传递参数 URL字符串中的alternatives=true。但它不会显示任何额外路径,只会显示一条路径。 我的URL代码:

Private String getDirectionsUrl(LatLng origin,LatLng dest)
{
    // Origin of route
    String str_origin = "origin="+origin.latitude+","+origin.longitude;

    // Destination of route
    String str_dest = "destination="+dest.latitude+","+dest.longitude;

    // Sensor enabled
    String sensor = "sensor=false";

    //Adding Alternative parameter
    String alternative = "alternatives=true";

    // Building the parameters to the web service
    String parameters = str_origin+"&"+str_dest+"&"+sensor+"&"+alternative;

    // Output format
    String output = "json";

    // Building the url to the web service
    String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters;

    return url;
}

1 个答案:

答案 0 :(得分:0)

  

alternatives - 如果设置为true,则指定Directions服务   可能在响应中提供多个路由替代方案。注意   提供路线选择可能会增加响应时间   服务器

你不会总是有其他选择!

Source