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
107 stars 132 forks source link

create a route with multi points #38

Closed gufrancisco closed 3 years ago

gufrancisco commented 4 years ago

Using "getRouteBetweenCoordinates" method, it is possible to create a route with more than 2 points (origin and destination).

For do this in flutter_polyline_points I propose the following changes: in archive flutter_polyline_points.dart add the a new method getRouteFromCoordinates

/// Get the list of coordinates from two or more geographical positions /// Future getRouteFromCoordinates( String googleApiKey, PointLatLng origin, PointLatLng destination, List wayPoints, {TravelMode travelMode = TravelMode.driving, bool avoidHighways = false, bool avoidTolls = false, bool avoidFerries = true, bool optimizeWaypoints = false}) async { return await util.getRouteFromCoordinates( googleApiKey, origin, destination, travelMode, wayPoints, avoidHighways, avoidTolls, avoidFerries, optimizeWaypoints); }

in archive netwok_util.dart add the a new method getRouteFromCoordinates

Future getRouteFromCoordinates( String googleApiKey, PointLatLng origin, PointLatLng destination, TravelMode travelMode, List wayPoints, bool avoidHighways, bool avoidTolls, bool avoidFerries, bool optimizeWaypoints) async { String mode = travelMode.toString().replaceAll('TravelMode.', ''); PolylineResult result = PolylineResult(); var params = { "origin": "${origin.latitude},${origin.longitude}", "destination": "${destination.latitude},${destination.longitude}", "mode": mode, "avoidHighways": "$avoidHighways", "avoidFerries": "$avoidFerries", "avoidTolls": "$avoidTolls", "key": googleApiKey }; if (wayPoints.isNotEmpty) { List wayPointsArray = List(); wayPoints.forEach((element) { wayPointsArray.add(element.location); }); String wayPointsString = wayPointsArray.join('|'); if (optimizeWaypoints) { wayPointsString = 'optimize:true|$wayPointsString'; } params.addAll({"waypoints": wayPointsString}); } Uri uri = Uri.https("maps.googleapis.com", "maps/api/directions/json", params);

String url = uri.toString();
print('GOOGLE MAPS URL: ' + url);
var response = await http.get(url);
if (response?.statusCode == 200) {
  var parsedJson = json.decode(response.body);
  result.status = parsedJson["status"];
  if (parsedJson["status"]?.toLowerCase() == STATUS_OK &&
      parsedJson["routes"] != null &&
      parsedJson["routes"].isNotEmpty) {
    result.points = decodeEncodedPolyline(
        parsedJson["routes"][0]["overview_polyline"]["points"]);
  } else {
    result.errorMessage = parsedJson["error_message"];
  }
}
return result;

}

If i have permition, i create a new feature branch and commit this for you analyze.

Dammyololade commented 4 years ago

Yes, you can go ahead @gufrancisco

gufrancisco commented 4 years ago

Yes, you can go ahead @gufrancisco

@Dammyololade, yet get denied permission to push my commit.

Dammyololade commented 4 years ago

ok, why dont you create a fork, and create a PR to this repositories when u are done, or should add you as a contributor?

Dammyololade commented 3 years ago

I cant find the implementation hence why i'm closing this