[英]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.