getRouteBetweenCoordinates method

Future<PolylineResult> getRouteBetweenCoordinates(
  1. String googleApiKey,
  2. PointLatLng origin,
  3. PointLatLng destination, {
  4. TravelMode travelMode = TravelMode.driving,
  5. List<PolylineWayPoint> wayPoints = const [],
  6. bool avoidHighways = false,
  7. bool avoidTolls = false,
  8. bool avoidFerries = true,
  9. bool optimizeWaypoints = false,
})

Get the list of coordinates between two geographical positions which can be used to draw polyline between this two positions

Implementation

Future<PolylineResult> getRouteBetweenCoordinates(
    String googleApiKey, PointLatLng origin, PointLatLng destination,
    {TravelMode travelMode = TravelMode.driving,
    List<PolylineWayPoint> wayPoints = const [],
    bool avoidHighways = false,
    bool avoidTolls = false,
    bool avoidFerries = true,
    bool optimizeWaypoints = false}) async {
  assert(googleApiKey.isNotEmpty, "Google API Key cannot be empty");
  try {
    var result = await NetworkUtil().getRouteBetweenCoordinates(
        request: PolylineRequest(
            apiKey: googleApiKey,
            origin: origin,
            destination: destination,
            mode: travelMode,
            wayPoints: wayPoints,
            avoidHighways: avoidHighways,
            avoidTolls: avoidTolls,
            avoidFerries: avoidFerries,
            alternatives: false,
            optimizeWaypoints: optimizeWaypoints));
    return result.isNotEmpty
        ? result[0]
        : PolylineResult(errorMessage: "No result found");
  } catch (e) {
    rethrow;
  }
}