Skip to content

Commit

Permalink
Merge pull request #13 from SamadiPour/patch-1
Browse files Browse the repository at this point in the history
Update responses based on latest documentation
  • Loading branch information
OlehMarch authored Jan 31, 2024
2 parents b23f60d + db114ff commit ab412cf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
8 changes: 4 additions & 4 deletions lib/src/directions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ class TravelMode {
static final values = <TravelMode>[bicycling, driving, transit, walking];

/// Specifies a bicycling directions request.
static const bicycling = TravelMode('bicycling');
static const bicycling = TravelMode('BICYCLING');

/// Specifies a driving directions request.
static const driving = TravelMode('driving');
static const driving = TravelMode('DRIVING');

/// Specifies a transit directions request.
static const transit = TravelMode('transit');
static const transit = TravelMode('TRANSIT');

/// Specifies a walking directions request.
static const walking = TravelMode('walking');
static const walking = TravelMode('WALKING');

@override
int get hashCode => _name.hashCode;
Expand Down
20 changes: 10 additions & 10 deletions lib/src/directions.request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class DirectionsRequest {
@override
String toString() => '?origin=${_convertLocation(origin)}&'
'destination=${_convertLocation(destination)}'
'${_addIfNotNull('mode', travelMode)}'
'${_addIfNotNull('mode', travelMode?.toString().toLowerCase())}'
'${_addIfNotNull('waypoints', _convertWaypoints())}'
'${_addIfNotNull('alternatives', alternatives)}'
'${_addIfNotNull('avoid', _convertAvoids())}'
Expand Down Expand Up @@ -429,9 +429,9 @@ class TransitOptions {

@override
String toString() =>
'${_addIfNotNull('arrival_time', arrivalTime!.millisecondsSinceEpoch)}'
'${_addIfNotNull('departure_time', departureTime!.millisecondsSinceEpoch)}'
'${_addIfNotNull('transit_mode', modes!.map((_) => _.toString()).join('|'))}'
'${_addIfNotNull('arrival_time', arrivalTime?.millisecondsSinceEpoch)}'
'${_addIfNotNull('departure_time', departureTime?.millisecondsSinceEpoch)}'
'${_addIfNotNull('transit_mode', modes?.map((_) => _.toString()).join('|'))}'
'${_addIfNotNull('transit_routing_preference', routingPreference)}';
}

Expand Down Expand Up @@ -556,7 +556,7 @@ class DrivingOptions {

@override
String toString() =>
'${_addIfNotNull('departure_time', departureTime!.millisecondsSinceEpoch)}'
'${_addIfNotNull('departure_time', departureTime?.millisecondsSinceEpoch)}'
'${_addIfNotNull('traffic_model', trafficModel)}';
}

Expand Down Expand Up @@ -628,23 +628,23 @@ class TransitMode {

/// Indicates that the calculated route should prefer travel
/// by bus.
static const bus = TransitMode('BUS');
static const bus = TransitMode('bus');

/// Indicates that the calculated route should prefer travel
/// by bus.
static const subway = TransitMode('SUBWAY');
static const subway = TransitMode('subway');

/// Indicates that the calculated route should prefer travel
/// by bus.
static const train = TransitMode('TRAIN');
static const train = TransitMode('train');

/// Indicates that the calculated route should prefer travel
/// by bus.
static const tram = TransitMode('TRAM');
static const tram = TransitMode('tram');

/// Indicates that the calculated route should prefer travel
/// by bus.
static const rail = TransitMode('RAIL');
static const rail = TransitMode('rail');

@override
String toString() => _name;
Expand Down
53 changes: 49 additions & 4 deletions lib/src/directions.response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ class Leg {
this.startAddress,
this.startLocation,
this.steps,
this.viaWaypoint,
});

factory Leg.fromMap(Map<String, dynamic> map) => Leg(
Expand All @@ -624,6 +625,8 @@ class Leg {
startAddress: map['start_address'] as String?,
startLocation: _getGeoCoordFromMap(map['start_location']),
steps: (map['steps'] as List?)?.mapList((_) => Step.fromMap(_)),
viaWaypoint: (map['via_waypoint'] as List?)
?.mapList((_) => ViaWaypoint.fromMap(_)),
);

/// Contains the estimated time of arrival for this leg. This property
Expand Down Expand Up @@ -715,6 +718,10 @@ class Leg {
/// contains an array of steps denoting information about each
/// separate step of the leg of the journey.
final List<Step>? steps;

/// The locations of via waypoints along this leg.
/// contains info about points through which the route was laid
final List<ViaWaypoint>? viaWaypoint;
}

/// Each element in the steps array defines a single step of the
Expand Down Expand Up @@ -791,6 +798,7 @@ class Step {
this.transit,
this.travelMode,
this.polyline,
this.maneuver,
});

factory Step.fromMap(Map<String, dynamic> map) => Step(
Expand All @@ -804,14 +812,15 @@ class Step {
instructions: map['html_instructions'] as String?,
path: (map['path'] as List?)?.mapList((_) => _getGeoCoordFromMap(_)),
steps: (map['steps'] as List?)?.mapList((_) => Step.fromMap(_)),
transit: map['transit'] != null
? TransitDetails.fromMap(map['transit'])
transit: map['transit_details'] != null
? TransitDetails.fromMap(map['transit_details'])
: null,
travelMode:
map['travel_mode'] != null ? TravelMode(map['travel_mode']) : null,
polyline: map['polyline'] != null
? OverviewPolyline.fromMap(map['polyline'])
: null,
maneuver: map['maneuver'] as String?,
);

/// Contains the distance covered by this step until the next
Expand Down Expand Up @@ -857,6 +866,10 @@ class Step {

/// Contains a points describing the course of this step.
final OverviewPolyline? polyline;

/// Contains the action to take for the current step (turn left, merge,
/// straight, etc.).
final String? maneuver;
}

/// Transit directions return additional information that is not
Expand Down Expand Up @@ -1242,7 +1255,9 @@ class Time {
factory Time.fromMap(Map<String, dynamic> map) => Time(
text: map['text'] as String?,
timeZone: map['time_zone'] as String?,
value: DateTime.tryParse(map['value'] as String),
value: map['value'] != null
? DateTime.fromMillisecondsSinceEpoch(map['value'] * 1000)
: null,
);

/// The time specified as a [String]. The time is displayed in the time
Expand Down Expand Up @@ -1365,7 +1380,7 @@ class Vehicle {
name: map['name'] as String?,
type: map['type'] != null ? VehicleType(map['type']) : null,
icon: map['icon'] as String?,
localIcon: map['localIcon'] as String?,
localIcon: map['local_icon'] as String?,
);

/// Contains the name of the vehicle on this line. eg. "Subway."
Expand All @@ -1382,6 +1397,32 @@ class Vehicle {
final String? localIcon;
}

/// The locations of via waypoints along this leg.
/// contains info about points through which the route was laid
class ViaWaypoint {
const ViaWaypoint({
this.location,
this.stepIndex,
this.stepInterpolation,
});

factory ViaWaypoint.fromMap(Map<String, dynamic> map) => ViaWaypoint(
location: _getGeoCoordFromMap(map['location']),
stepIndex: map['step_index'] as int?,
stepInterpolation: map['step_interpolation'] as num?,
);

/// The location of the waypoint.
final GeoCoord? location;

/// The index of the step containing the waypoint.
final int? stepIndex;

/// The position of the waypoint along the step's polyline,
/// expressed as a ratio from 0 to 1.
final num? stepInterpolation;
}

/// The status field within the Directions response object contains
/// the status of the request, and may contain debugging information
/// to help you track down why the Directions service failed.
Expand Down Expand Up @@ -1476,6 +1517,7 @@ class VehicleType {
heavyRail,
highSpeedTrain,
intercityBus,
longDistanceTrain,
metroRail,
monorail,
other,
Expand Down Expand Up @@ -1514,6 +1556,9 @@ class VehicleType {
/// Intercity bus.
static const intercityBus = VehicleType('INTERCITY_BUS');

/// Long distance train.
static const longDistanceTrain = VehicleType('LONG_DISTANCE_TRAIN');

/// Light rail.
static const metroRail = VehicleType('METRO_RAIL');

Expand Down

0 comments on commit ab412cf

Please sign in to comment.