Skip to content

Commit

Permalink
Merge pull request #93 from nextbillion-ai/feat/support_fast_option
Browse files Browse the repository at this point in the history
(feat) add fast option in route request params
  • Loading branch information
zhengshenqiu authored Aug 7, 2024
2 parents f6afd53 + cceab0f commit 3d87c74
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ai.nextbillion.navigation.ui.route.DefaultWayPointStyle
import ai.nextbillion.navigation.ui.view.DurationSymbol
import android.app.Activity
import android.graphics.Bitmap
import android.text.TextUtils
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import org.json.JSONException
Expand Down Expand Up @@ -126,7 +127,11 @@ class RouteFetcherHandler(methodChannel: MethodChannel?) : MethodChannelHandler(
return
}
val params = RouteRequestParams.fromJson(data.toString())
RouteFetcher.getRoute(params, object : Callback<DirectionsResponse> {
val paramsBuilder = params.toBuilder()
if (TextUtils.equals(params.option(), "fast")) {
paramsBuilder.option(null)
}
RouteFetcher.getRoute(paramsBuilder.build(), object : Callback<DirectionsResponse> {
override fun onResponse(call: Call<DirectionsResponse>, response: Response<DirectionsResponse>) {
val args = mutableMapOf<String, Any>()
if (response.code() >= 200 && response.code() < 300) {
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/Convert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Convert {

static let mapOptions = [
"flexible": NBMapOption.valhalla,
"none": NBMapOption.none
"fast": NBMapOption.none
]

static let measurements = [
Expand Down
11 changes: 9 additions & 2 deletions lib/model/route_request_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ class RouteRequestParams {
/// waypoints that these are the non-snapped coordinates.
List<LatLng>? waypoints;

///Use this option to switch to truck-specific routing or time based routing
///or if you want to choose between the fastest and shortest route types
/// Allowed Values:
/// [SupportedOption.fast] gets the directions and route guidance in real time for trips starting at current time.
/// The routes returned through this service have the traffic conditions factored in to avoid any delays under usual circumstances.
///
/// [SupportedOption.flexible] offers customizable features for advanced navigation experience.
/// It serves requests for truck specific routing, time based routing, allows choosing between fastest and shortest route types and also offers to return segment-wise speed limits of the route suggested.
/// The traffic conditions are also factored in by the service to avoid delays under usual circumstances.
///
/// The default is [SupportedOption.fast].
SupportedOption? option;

/// The format of the returned geometry. Allowed values are:
Expand Down
6 changes: 4 additions & 2 deletions lib/model/route_request_params_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ enum SupportedGeometry {
}

enum SupportedOption {
flexible;
flexible,
fast;

static SupportedOption? fromValue(String? s) => switch (s) {
"flexible" => flexible,
_ => null,
"fast" => fast,
_ => fast,
};
}

Expand Down
4 changes: 2 additions & 2 deletions test/model/route_request_params_constants_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ void main() {
test('SupportedOption.fromValue should return SupportedOption', () {
expect(SupportedOption.fromValue('flexible'),
equals(SupportedOption.flexible));
expect(SupportedOption.fromValue(null), equals(null));
expect(SupportedOption.fromValue('invalid'), equals(null));
expect(SupportedOption.fromValue(null), equals(SupportedOption.fast));
expect(SupportedOption.fromValue('invalid'), equals(SupportedOption.fast));
});

test('SupportedHazmatType.fromValue should return SupportedHazmatType', () {
Expand Down

0 comments on commit 3d87c74

Please sign in to comment.