Open
Description
Add a section to our maps guide on drawing driving directions:
public void drawDirections(GoogleMap map, fromLatLng, toLatLng) {
GoogleDirection.withServerKey("YOUR_SERVER_API_KEY")
.from(new LatLng(37.7681994, -122.444538))
.to(new LatLng(37.7749003,-122.4034934))
.avoid(AvoidType.FERRIES)
.avoid(AvoidType.HIGHWAYS)
.execute(new DirectionCallback() {
@Override
public void onDirectionSuccess(Direction direction) {
if(direction.isOK()) {
onDirectionSuccess(direction);
} else {
// Error case
}
}
@Override
public void onDirectionFailure(Throwable t) {
// Error case
}
});
}
@Override
public void onDirectionSuccess(Direction direction) {
// Draw markers
googleMap.addMarker(new MarkerOptions().position(origin));
googleMap.addMarker(new MarkerOptions().position(destination));
// Draw lines
ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint();
googleMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 5, Color.RED));
}
Other: