getRouteDirectionsGeoJson method

Future<GeoJsonFeatureCollection> getRouteDirectionsGeoJson({
  1. required Coordinate startCoordinate,
  2. required Coordinate endCoordinate,
  3. ORSProfile? profileOverride,
})

Fetches the Direction Route information for the route between startCoordinate and endCoordinate from the openrouteservice API, and returns the entire geojson GeoJsonFeatureCollection containing the data.

To get only the parsed route coordinates, use ORSDirections.getRouteCoordinates.

Information about the endpoint, parameters, response etc. can be found at: https://openrouteservice.org/dev/#/api-docs/v2/directions/{profile}/get

Implementation

Future<GeoJsonFeatureCollection> getRouteDirectionsGeoJson({
  required Coordinate startCoordinate,
  required Coordinate endCoordinate,
  ORSProfile? profileOverride,
}) async {
  // If a path parameter override is provided, use it.
  final ORSProfile chosenPathParam = profileOverride ?? _profile;

  // Extract coordinate information.
  final double startLat = startCoordinate.latitude;
  final double startLng = startCoordinate.longitude;
  final double endLat = endCoordinate.latitude;
  final double endLng = endCoordinate.longitude;

  // Build the request URL.
  final Uri uri = Uri.parse(
    '$_directionsEndpointURL/${OpenRouteService.getProfileString(chosenPathParam)}?api_key=$_apiKey&start=$startLng,$startLat&end=$endLng,$endLat',
  );

  // Fetch the data.
  final Map<String, dynamic> data = await _openRouteServiceGet(uri: uri);
  return GeoJsonFeatureCollection.fromJson(data);
}