flutterfluttermapopenrouteservice

how to set avoid_polygons in open_route_service package in flutter


I'm building a mapping application using Flutter and the openrouteservice API to get directions between two points. I want to customize the route by avoiding certain areas or polygons defined by their coordinates. Specifically, I have a polygon defined by a set of coordinates, and I want to make sure the route doesn't pass through it.

I've successfully retrieved the route coordinates using directionsMultiRouteCoordsPost, but I'm not sure how to integrate the avoid polygons option. Here's the code I'm currently using:

    final List<ORSCoordinate> routeCoordinates2 = await openrouteservice.directionsMultiRouteCoordsPost(coordinates: [
  ORSCoordinate(latitude: 8.920576, longitude: 125.576619),
  ORSCoordinate(
    latitude: endTappedLocation!.latitude,
    longitude: endTappedLocation!.longitude,
  ),
]);

And here are the coordinates of the polygon to avoid:

    points: [
  LatLng(8.923613, 125.575063),
  LatLng(8.920441, 125.573503),
  LatLng(8.923704, 125.567126),
  LatLng(8.926735, 125.568404)
],

Can someone please help me understand how to add the avoid polygons option to my directionsMultiRouteCoordsPost function to get an alternative route that avoids the polygon? Thank you in advance."


Solution

  • Creator of open_route_service here. This problem has probably been solved by now. But just for future reference, as per openrouteservice docs, it seems like all you need to do is pass the map {"avoid_polygons": {"empty": ...}} in the options parameter of directionsMultiRouteCoordsPost method of the package API, just as it is passed in Directions POST APIs.

    Like I have mentioned before, I would love it if the community opens up issues in the repository itself whenever there is any confusion/problem/discussion to be had, as it is very hard to find issues spread all over the internet. :)