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

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

Closed
wants to merge 6 commits into from

Conversation

aaqibismail
Copy link

@aaqibismail aaqibismail commented Jul 2, 2021

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
Copy link

bluemix commented Jul 17, 2021

please merge this

@ziagit
Copy link

ziagit commented Feb 19, 2022

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

@aaqibismail
Copy link
Author

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
Copy link

ziagit commented Feb 20, 2022

@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
Copy link
Author

aaqibismail commented Feb 21, 2022

@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
Copy link

ziagit commented Feb 21, 2022

@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
Copy link

ziagit commented Feb 21, 2022

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
Copy link

ziagit commented Feb 23, 2022 via email

@speedlightwp
Copy link

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

Thanks

@aaqibismail
Copy link
Author

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
Copy link

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

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

Successfully merging this pull request may close these issues.

None yet

5 participants