mirror of
https://github.com/Iconica-Development/flutter_google_track_and_trace.git
synced 2025-05-19 05:03:45 +02:00
Fix route calculation error when no route has been found
This commit is contained in:
parent
f7b455e53e
commit
1951e6a4fd
2 changed files with 20 additions and 13 deletions
|
@ -6,7 +6,7 @@ class DirectionsRepository {
|
|||
static const String _baseUrl = '/maps/api/directions/json';
|
||||
|
||||
/// get the route between the two coordinates
|
||||
Future<Directions> getDirections({
|
||||
Future<Directions?> getDirections({
|
||||
required LatLng origin,
|
||||
required LatLng destination,
|
||||
required TravelMode mode,
|
||||
|
@ -32,7 +32,11 @@ class DirectionsRepository {
|
|||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
return Directions.fromMap(jsonDecode(response.body));
|
||||
} on GoogleMapsException catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} on HttpException catch (e) {
|
||||
debugPrint(e.message);
|
||||
|
|
|
@ -237,17 +237,20 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
|
|||
key: widget.googleAPIKey,
|
||||
)
|
||||
.then(
|
||||
(value) => {
|
||||
(Directions? directions) => {
|
||||
if (directions != null)
|
||||
{
|
||||
controller.route = TrackTraceRoute(
|
||||
value.totalDuration,
|
||||
value.totalDistance,
|
||||
value.polylinePoints,
|
||||
directions.totalDuration,
|
||||
directions.totalDistance,
|
||||
directions.polylinePoints,
|
||||
),
|
||||
checkDestinationCloseBy(),
|
||||
controller.recenterCamera(),
|
||||
setState(() {
|
||||
lastRouteUpdate = DateTime.now();
|
||||
}),
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue