Dammyololade / flutter_polyline_points

A flutter plugin that's decodes encoded google poly line string into list of geo-coordinates suitable for showing route/polyline on maps
MIT License
109 stars 132 forks source link

Added support for multiple/alternate routes, update dependencies #62

Closed aaqibismail closed 5 months ago

aaqibismail commented 3 years ago

Added an extra parameter, alternatives, from Google Maps API Docs for receiving multiple routes. Solves #61, #63

Adds models for bounds, legs, status_codes, and geocoded_waypoints from the json response received from the API. Updated avoid parameter according to Google Maps Documentation. Added function to parse json body to use for server-side API calls that return the json data. Supports both coordinate or place_id for origin and destination.

bluemix commented 3 years ago

please merge this

ziagit commented 2 years ago

How to use or add alternative parameter in my code, there is no code related to alternate routes in the example

aaqibismail commented 2 years ago

How to use or add alternative parameter in my code, there is no code related to alternate routes in the example

Take a look at my first commit

ziagit commented 2 years ago

@aaqibism at your first commit

   if (result.points.isNotEmpty) {
      result.points.forEach((PointLatLng point) {
      result.points.first.forEach((PointLatLng point) {
        polylineCoordinates.add(LatLng(point.latitude, point.longitude));
      });
    }

in the inner loop result.points.first.forEach() forEach is not defined, at mouse hover showing this

The method 'forEach' isn't defined for the type 'PointLatLng'.
Try correcting the name to the name of an existing method, or defining a method named 'forEach'.dart[undefined_method](https://dart.dev/diagnostics/undefined_method)

Isn't there any example code to share with me please.

aaqibismail commented 2 years ago

@aaqibism at your first commit

   if (result.points.isNotEmpty) {
      result.points.forEach((PointLatLng point) {
      result.points.first.forEach((PointLatLng point) {
        polylineCoordinates.add(LatLng(point.latitude, point.longitude));
      });
    }

in the inner loop result.points.first.forEach() forEach is not defined, at mouse hover showing this

The method 'forEach' isn't defined for the type 'PointLatLng'.
Try correcting the name to the name of an existing method, or defining a method named 'forEach'.dart[undefined_method](https://dart.dev/diagnostics/undefined_method)

Isn't there any example code to share with me please.

I think you’re looking at the wrong example. Look in example/lib/main.dart

if (result.routes[0].points.isNotEmpty) {
       result.routes[0].points.forEach((PointLatLng point) {
         polylineCoordinates.add(LatLng(point.latitude, point.longitude));
       });
ziagit commented 2 years ago

@aaqibism at your first commit

   if (result.points.isNotEmpty) {
      result.points.forEach((PointLatLng point) {
      result.points.first.forEach((PointLatLng point) {
        polylineCoordinates.add(LatLng(point.latitude, point.longitude));
      });
    }

in the inner loop result.points.first.forEach() forEach is not defined, at mouse hover showing this

The method 'forEach' isn't defined for the type 'PointLatLng'.
Try correcting the name to the name of an existing method, or defining a method named 'forEach'.dart[undefined_method](https://dart.dev/diagnostics/undefined_method)

Isn't there any example code to share with me please.

I think you’re looking at the wrong example. Look in example/lib/main.dart

if (result.routes[0].points.isNotEmpty) {
       result.routes[0].points.forEach((PointLatLng point) {
         polylineCoordinates.add(LatLng(point.latitude, point.longitude));
       });
ziagit commented 2 years ago

Dear @aaqibism The getter 'routes' isn't defined for the type 'PolylineResult' This is my function which drawing polyline, is there anything I'm doing wrong?

  _getPolyline(lat1, lng1, lat2, lng2) async {
    PolylineResult result = await polylinePoints
        .getRouteBetweenCoordinates(
      mapKey,
      PointLatLng(lat1, lng1),
      PointLatLng(lat2, lng2),
      travelMode: TravelMode.driving,
    )
        .catchError((onError) {
      showSnackbar(context, "An Error Occured Possibly due to network issues");
    });
    print(result.routes); 
    if (result.points.isNotEmpty) {
      polylineCoordinates = [];
      result.points.forEach((PointLatLng point) {
        polylineCoordinates.add(LatLng(point.latitude, point.longitude));
      });
    }
    _addPolyLine();
  }
  _addPolyLine() {
    PolylineId id = PolylineId("Poly");
    Polyline polyline = Polyline(
      polylineId: id,
      width: 4,
      startCap: Cap.roundCap,
      endCap: Cap.buttCap,
      color: Colors.blue,
      points: polylineCoordinates,
    );
    polylines[id] = polyline;
  }

when I print(result.routes) routes is not defined for result, It seems you have not merged yet because in example/lib/main.dart the code looks like this

_getPolyline() async {
    PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
        googleAPiKey,
        PointLatLng(_originLatitude, _originLongitude),
        PointLatLng(_destLatitude, _destLongitude),
        travelMode: TravelMode.driving,
        wayPoints: [PolylineWayPoint(location: "Sabo, Yaba Lagos Nigeria")]);
    if (result.points.isNotEmpty) {
      result.points.forEach((PointLatLng point) {
        polylineCoordinates.add(LatLng(point.latitude, point.longitude));
      });
    }
    _addPolyLine();
  }
ziagit commented 2 years ago

Dear Aqib, can you merge polyline support changes to the branch we can access.

Thanks

On Mon, Feb 21, 2022 at 6:14 AM Aaqib Ismail @.***> wrote:

@aaqibism https://github.com/aaqibism at your first commit

if (result.points.isNotEmpty) {

  result.points.forEach((PointLatLng point) {

  result.points.first.forEach((PointLatLng point) {

    polylineCoordinates.add(LatLng(point.latitude, point.longitude));

  });

}

in the inner loop result.points.first.forEach() forEach is not defined, at mouse hover showing this

The method 'forEach' isn't defined for the type 'PointLatLng'.

Try correcting the name to the name of an existing method, or defining a method named 'forEach'.dartundefined_method

Isn't there any example code to share with me please.

I think you’re looking at the wrong example. Look at in example/lib/main.dart

if (result.routes[0].points.isNotEmpty) {

   result.routes[0].points.forEach((PointLatLng point) {

     polylineCoordinates.add(LatLng(point.latitude, point.longitude));

   });

— Reply to this email directly, view it on GitHub https://github.com/Dammyololade/flutter_polyline_points/pull/62#issuecomment-1046924425, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKQBVPW7IZCHPD2PSQSAGJDU4JCGDANCNFSM47XNITQA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

-- @.*** Zia Akbari

speedlightwp commented 2 years ago

Dear @aaqibism , can you merge polyline support changes to the branch we can access.

Thanks

aaqibismail commented 2 years ago

Dear @aaqibism , can you merge polyline support changes to the branch we can access.

Thanks

I’m not the owner of the repo, I don’t know how to otherwise.

speedlightwp commented 2 years ago

Dear @Dammyololade, would you be able to do something about it?