Skip to content

Commit

Permalink
Merge pull request #15 from Dammyololade/master
Browse files Browse the repository at this point in the history
Merge pull request #12 from Dammyololade/development
  • Loading branch information
Dammyololade authored Aug 22, 2020
2 parents 62e5e28 + 1d44f79 commit 3c17337
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
19 changes: 9 additions & 10 deletions lib/flutter_polyline_points.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ class PolylinePoints {
/// which can be used to draw polyline between this two positions
///
Future<PolylineResult> getRouteBetweenCoordinates(
String googleApiKey,
PointLatLng origin,
PointLatLng destination, {
TravelMode travelMode = TravelMode.driving,
List<PolylineWayPoint> wayPoints = const [],
bool avoidHighways = false,
bool avoidTolls = false,
bool avoidFerries = true,
}) async {
String googleApiKey, PointLatLng origin, PointLatLng destination,
{TravelMode travelMode = TravelMode.driving,
List<PolylineWayPoint> wayPoints = const [],
bool avoidHighways = false,
bool avoidTolls = false,
bool avoidFerries = true,
bool optimizeWaypoints = false}) async {
return await util.getRouteBetweenCoordinates(
googleApiKey,
origin,
Expand All @@ -38,7 +36,8 @@ class PolylinePoints {
wayPoints,
avoidHighways,
avoidTolls,
avoidFerries);
avoidFerries,
optimizeWaypoints);
}

/// Decode and encoded google polyline
Expand Down
30 changes: 17 additions & 13 deletions lib/src/network_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class NetworkUtil {
///Get the encoded string from google directions api
///
Future<PolylineResult> getRouteBetweenCoordinates(
String googleApiKey,
PointLatLng origin,
PointLatLng destination,
TravelMode travelMode,
List<PolylineWayPoint> wayPoints,
bool avoidHighways,
bool avoidTolls,
bool avoidFerries,
) async {
String googleApiKey,
PointLatLng origin,
PointLatLng destination,
TravelMode travelMode,
List<PolylineWayPoint> wayPoints,
bool avoidHighways,
bool avoidTolls,
bool avoidFerries,
bool optimizeWaypoints) async {
String mode = travelMode.toString().replaceAll('TravelMode.', '');
PolylineResult result = PolylineResult();
var params = {
Expand All @@ -34,11 +34,15 @@ class NetworkUtil {
"key": googleApiKey
};
if (wayPoints.isNotEmpty) {
params.addAll({
"waypoints": json.encode(List.from(wayPoints.map((e) => e.toMap())))
});
List<String> wayPointsArray = wayPoints.map((point) => point.toString());
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);
Uri uri =
Uri.https("maps.googleapis.com", "maps/api/directions/json", params);

String url = uri.toString();
print('GOOGLE MAPS URL: ' + url);
Expand Down
17 changes: 7 additions & 10 deletions lib/src/utils/polyline_waypoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import 'package:flutter/material.dart';

/// description:
/// project: flutter_polyline_points
/// @package:
/// @package:
/// @author: dammyololade
/// created on: 12/05/2020
class PolylineWayPoint {

/// the location of the waypoint,
/// You can specify waypoints using the following values:
/// --- Latitude/longitude coordinates (lat/lng): an explicit value pair. (-34.92788%2C138.60008 comma, no space),
Expand All @@ -20,16 +19,14 @@ class PolylineWayPoint {
/// which has the effect of splitting the route into two routes
bool stopOver;


PolylineWayPoint({@required this.location, this.stopOver = true});

Map<String, dynamic> toMap() => {
"location": location,
"stopover": stopOver
};

@override
String toString() {
return "location=$location,stopover=$stopOver";
if (stopOver) {
return location;
} else {
return "via:$location";
}
}
}
}

0 comments on commit 3c17337

Please sign in to comment.