我已经创建了一个地图,用户可以在其中从A点导航到B点(使用google-maps api),现在我陷入了第三点。
所以我的想法是创建一个起点(当前位置),该起点将绘制一条路线到A点以及从A点到B点。
StartLocation-点A-点B。
此时,我可以画出一条从点a到点b的路线。
private String getRequestUrl(LatLng origin, LatLng dest) {
//Setup the origin
String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
//Setup the destination
String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
//Setup sensor
String str_sensor = "sensor=false";
//Setup mode
String str_mode = "mode=driving";
//Setup path
String str_path = str_origin + "&" + str_dest + "&" + str_sensor + "&" + str_mode;
//Setup output
String output = "json";
//Setup API key
String key = "key=MY-API-KEY";
//URL for the data
String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + str_path + "&" + key;
return url;
}
那么我如何添加其他目的地?还有其他网址可以嵌入3个或更多位置吗?请让我知道。
答案 0 :(得分:0)
您可以使用this库。检查示例使用
LatLng start = new LatLng(18.015365, -77.499382);
LatLng waypoint= new LatLng(18.01455, -77.499333);
LatLng end = new LatLng(18.012590, -77.500659);
Routing routing = new Routing.Builder()
.travelMode(Routing.TravelMode.WALKING)
.withListener(this)
.waypoints(start, waypoint, end)
.build();
routing.execute();
@Override
public void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex)
{
//code to add route to map here. See sample app for more details.
}