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';
|
static const String _baseUrl = '/maps/api/directions/json';
|
||||||
|
|
||||||
/// get the route between the two coordinates
|
/// get the route between the two coordinates
|
||||||
Future<Directions> getDirections({
|
Future<Directions?> getDirections({
|
||||||
required LatLng origin,
|
required LatLng origin,
|
||||||
required LatLng destination,
|
required LatLng destination,
|
||||||
required TravelMode mode,
|
required TravelMode mode,
|
||||||
|
@ -32,7 +32,11 @@ class DirectionsRepository {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return Directions.fromMap(jsonDecode(response.body));
|
try {
|
||||||
|
return Directions.fromMap(jsonDecode(response.body));
|
||||||
|
} on GoogleMapsException catch (_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} on HttpException catch (e) {
|
} on HttpException catch (e) {
|
||||||
debugPrint(e.message);
|
debugPrint(e.message);
|
||||||
|
|
|
@ -237,17 +237,20 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
|
||||||
key: widget.googleAPIKey,
|
key: widget.googleAPIKey,
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
(value) => {
|
(Directions? directions) => {
|
||||||
controller.route = TrackTraceRoute(
|
if (directions != null)
|
||||||
value.totalDuration,
|
{
|
||||||
value.totalDistance,
|
controller.route = TrackTraceRoute(
|
||||||
value.polylinePoints,
|
directions.totalDuration,
|
||||||
),
|
directions.totalDistance,
|
||||||
checkDestinationCloseBy(),
|
directions.polylinePoints,
|
||||||
controller.recenterCamera(),
|
),
|
||||||
setState(() {
|
checkDestinationCloseBy(),
|
||||||
lastRouteUpdate = DateTime.now();
|
controller.recenterCamera(),
|
||||||
}),
|
setState(() {
|
||||||
|
lastRouteUpdate = DateTime.now();
|
||||||
|
}),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue