使用基于最小距离google方向的路标来优化路径android

时间:2018-02-08 18:33:31

标签: android google-maps google-direction

我正在使用谷歌路线api获取两个latlng点之间的路线并将其绘制在谷歌地图上。问题是我可以在添加航路点时优化路线,但我无法控制优化标准。我用于创建请求网址的代码是:

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";

    // Waypoints
    String waypoints = "";
    for (int i = 0; i < markerPoints.size(); i++) {

        LatLng point = (LatLng) markerPoints.get(i);
        if (i == 0)
            waypoints = "waypoints=optimize:true|";
        if (i == markerPoints.size() - 1) {
            waypoints += point.latitude + "," + point.longitude;
        } else {
            waypoints += point.latitude + "," + point.longitude + "|";
        }
    }

    // Building the parameters to the web service
    String parameters = str_origin + "&" + str_dest + "&" + sensor + "&" + waypoints + "&mode=driving&key=YOUR_API_KEY";


    // 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;
}

简而言之,我想在此字符串中添加优化条件。是否可以或者我必须启用备用路线并手动计算每条路径的行程距离并选择最短路径?

0 个答案:

没有答案