Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select TravelMode When Direction request #45

Open
joumduk opened this issue Jul 7, 2020 · 1 comment
Open

Select TravelMode When Direction request #45

joumduk opened this issue Jul 7, 2020 · 1 comment

Comments

@joumduk
Copy link

joumduk commented Jul 7, 2020

Use case

I want to provide transit route (such as bus, subway route ) for user.
but, The plugin is not supported select TravelMode for direction

Proposal

AddDirection function will be can add with TravelMode like option.
and provide route of this TravelMode

`
@OverRide
void addDirection(dynamic origin, dynamic destination,
{String startLabel,
String startIcon,
String startInfo,
String endLabel,
String endIcon,
String endInfo,
TravelMode mode}) {
assert(() {
if (origin == null) {
throw ArgumentError.notNull('origin');
}

  if (destination == null) {
    throw ArgumentError.notNull('destination');
  }

  return true;
}());
if (mode == null) {
  mode = TravelMode.DRIVING;
}

_directions.putIfAbsent(
  '${origin}_$destination',
  () {
    DirectionsRenderer direction = DirectionsRenderer(
        DirectionsRendererOptions()..suppressMarkers = true);
    direction.map = _map;
    final transitMode = TransitOptions();
    transitMode.modes = [
      TransitMode.RAIL,
      TransitMode.SUBWAY,
      TransitMode.TRAIN
    ];
    final request = DirectionsRequest()
      ..origin = origin is GeoCoord
          ? LatLng(origin.latitude, origin.longitude)
          : origin
      ..destination =
          destination is GeoCoord ? destination.toLatLng() : destination
      ..travelMode = mode;
    if (mode == TravelMode.TRANSIT) {
      request..transitOptions = transitMode;
    }
    directionsService.route(
      request,
      (response, status) {
        if (status == DirectionsStatus.OK) {
          direction.directions = response;
          final leg = response?.routes?.firstOrNull?.legs?.firstOrNull;

          final startLatLng = leg?.startLocation;
          if (startLatLng != null) {
            if (startIcon != null ||
                startInfo != null ||
                startLabel != null) {
              addMarkerRaw(
                startLatLng.toGeoCoord(),
                icon: startIcon,
                info: startInfo ?? leg.startAddress,
                label: startLabel,
              );
            } else {
              addMarkerRaw(
                startLatLng.toGeoCoord(),
                icon: 'assets/images/marker_a.png',
                info: leg.startAddress,
              );
            }
          }

          final endLatLng = leg?.endLocation;
          if (endLatLng != null) {
            if (endIcon != null || endInfo != null || endLabel != null) {
              addMarkerRaw(
                endLatLng.toGeoCoord(),
                icon: endIcon,
                info: endInfo ?? leg.endAddress,
                label: endLabel,
              );
            } else {
              addMarkerRaw(
                endLatLng.toGeoCoord(),
                icon: 'assets/images/marker_b.png',
                info: leg.endAddress,
              );
            }
          }
        }
      },
    );

    return direction;
  },
);`
@joumduk joumduk changed the title How to select TravelMode for Direction request Select TravelMode When Direction request Jul 9, 2020
@AhmedAlbashaDev
Copy link

Hello
any solutions to this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants