【问题标题】:How to get direction between 3 points, from maps.googleapis如何从 maps.googleapis 获取 3 点之间的方向
【发布时间】:2017-08-25 06:05:31
【问题描述】:

如何在 3 个点之间获取方向,例如从 A 到 B 到 C。我当前的代码是从 2 个点获取方向。

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

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

        // Output format
        String output = "json";

        // Building the url to the web service
        String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters + "&key=" + getResources().getString(R.string.googleApiKey);

        return url;
    }

【问题讨论】:

    标签: java android google-maps google-api routes


    【解决方案1】:

    我认为路线 API 只有一个起点和终点。但是 API 有一个称为航路点的功能,它允许您通过一个或多个其他点来安排行程。如果您的原始行程是A -> C,而您现在想在B 添加停靠点,那么您可以添加一个航点,以确保行程经过B

    来自documentation,这是一个带有两个航点的示例 URL:

    https://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&
    destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&key=YOUR_API_KEY 
    

    【讨论】:

      猜你喜欢
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-10
      • 1970-01-01
      相关资源
      最近更新 更多