简体   繁体   English

如何在android&xamarin android中的源和目的地的Google地图上显示所有可能的路线?

[英]How to Show all possible routes on google map for source and destination in android & xamarin android?

我正在xamarin android中工作,并试图显示2个地理位置的Google地图(如google map android)上所有可能的路线,我可以使用google direction api显示单个路线,因此任何人都可以帮助我解决这个问题。

Try setting alternative to true. 尝试将Alternative设置为true。 According to the document : 根据文件

alternatives — If set to true , specifies that the Directions service may provide more than one route alternative in the response. 替代方案 —如果设置为true ,则指定“方向”服务可以在响应中提供多个路线替代方案。 Note that providing route alternatives may increase the response time from the server. 请注意,提供路由选择可能会增加服务器的响应时间。

Here is the sample code for handling the response : 这是处理响应的示例代码:

protected void onPostExecute(List<List<HashMap<String, String>>> result) {
  ArrayList<LatLng> points = null;
  PolylineOptions lineOptions = null;
  MarkerOptions markerOptions = new MarkerOptions();
  String distance = "";
  String duration = "";

  if(result.size()<1){
      Toast.makeText(getBaseContext(), "No Points", Toast.LENGTH_SHORT).show();
      return;
  }

  // Traversing through all the routes
  for(int i=0;i<result.size();i++){
      points = new ArrayList<LatLng>();
      lineOptions = new PolylineOptions();

      // Fetching i-th route
      List<HashMap<String, String>> path = result.get(i);

      // Fetching all the points in i-th route
      for(int j=0;j<path.size();j++){
          HashMap<String,String> point = path.get(j);

         if(j==0){    // Get distance from the list
              distance = (String)point.get("distance");
              continue;
          }else if(j==1){ // Get duration from the list
              duration = (String)point.get("duration");
              continue;
          }

          double lat = Double.parseDouble(point.get("lat"));
          double lng = Double.parseDouble(point.get("lng"));
          LatLng position = new LatLng(lat, lng);

          points.add(position);
      }

      // Adding all the points in the route to LineOptions
      lineOptions.addAll(points);
      lineOptions.width(4);
      lineOptions.color(Color.CYAN);


  tvDistanceDuration.setText("Distance:"+distance + ", Duration:"+duration);

  // Drawing polyline in the Google Map for the i-th route
  map.addPolyline(lineOptions);
    }
  }
}

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android上检索当前的Google地图目的地? - How to retrieve current Google map destination on Android? 如何在Android中找到绝对速度,距离,距离谷歌地图的源和目的地的速度 - how to find absolute speed,distance,speed from source and destination of google map in android 如何将KML文件路由添加到Xamarin.Forms.Android谷歌地图? - How to add KML-file routes to a Xamarin.Forms.Android google map? Xamarin 安卓谷歌地图 - Xamarin android google map 是否可以在Android Wear上显示Google地图视图? - Is it possible to show Google map view on Android Wear? 如何在Android中的地图上为源和目的地添加两个标记 - How to add two markers on map for source and destination in Android 如何使用android显示源到目的地的实时方向 - how to show live direction of a source to destination using android 如何使用源、目的地、开始时间和(开始时间 + 小时)作为谷歌地图 API 的输入在 android 中获取用户在谷歌地图上的位置 - How to get user location on google map with source, destination, start time, and (start time + hours) as input to Google Maps API in android 在Google Maps中查找从源到目的地的所有路线 - Find all routes from source to destination in google maps Xamarin Android-Google Map Marker始终显示相同信息 - Xamarin Android - Google Map Marker always show the same info
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM