Closed ericywl closed 6 years ago
Sound cool! Thanks for your request.
I will add
and(List<LatLng> waypoints)
for unspecified amount of waypoints for the next version.
For now, you can implement unspecific amount of waypoints like this.
String serverKey = ...
LatLng origin = ...
LatLng destination = ...
List<LatLng> waypoints = ...
DirectionDestinationRequest destinationRequest = GoogleDirection.withServerKey(serverKey)
.from(origin);
for (int index = 0; index < waypoints.size(); index++) {
destinationRequest.and(waypoints.get(index));
}
destinationRequest.to(destination)
.transportMode(TransportMode.DRIVING)
.execute(new DirectionCallback() {
@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
// TODO Do something
}
@Override
public void onDirectionFailure(Throwable t) {
// TODO Do something
}
});
But the code looks ugly.
Thanks for the help :)
I just updated my library to 1.1.1 with unspecified amount of waypoints supported
You can write the code like this
String serverKey = ...
LatLng origin = ...
LatLng destination = ...
List<LatLng> waypoints = ...
DirectionDestinationRequest destinationRequest = GoogleDirection.withServerKey(serverKey)
.from(origin)
.and(waypoints)
.to(destination)
.transportMode(TransportMode.DRIVING)
.execute(new DirectionCallback() {
@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
// TODO Do something
}
@Override
public void onDirectionFailure(Throwable t) {
// TODO Do something
}
});
Currently the waypoints seem to be hardcoded into GoogleDirection. Is it possible to implement .and( ) multiple times in something like a for loop? So let's say I have 5 waypoints, it will add 5 waypoints into the map. But another case, I may have 7, how do I handle this?