-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathnavigationUtils.ts
More file actions
91 lines (86 loc) · 3.04 KB
/
navigationUtils.ts
File metadata and controls
91 lines (86 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Alert } from 'react-native';
import {
RouteStatus,
type NavigationController,
type ContinueToNextDestinationResponse,
} from '@googlemaps/react-native-navigation-sdk';
import { showSnackbar } from './snackbar';
/**
* Handles a RouteStatus result from setDestinations or continueToNextDestination.
* Shows appropriate user feedback and returns whether the route was successful.
*
* @param routeStatus - The route status to handle.
* @returns true if the route status is OK, false otherwise.
*/
export const handleRouteStatus = (routeStatus: RouteStatus): boolean => {
switch (routeStatus) {
case RouteStatus.OK:
showSnackbar('Route created successfully');
return true;
case RouteStatus.ROUTE_CANCELED:
Alert.alert('Error', 'Route Cancelled');
return false;
case RouteStatus.NO_ROUTE_FOUND:
Alert.alert('Error', 'No Route Found');
return false;
case RouteStatus.NETWORK_ERROR:
Alert.alert('Error', 'Network Error');
return false;
case RouteStatus.LOCATION_DISABLED:
Alert.alert('Error', 'Location Disabled');
return false;
case RouteStatus.LOCATION_UNKNOWN:
Alert.alert('Error', 'Location Unknown');
return false;
case RouteStatus.DUPLICATE_WAYPOINTS_ERROR:
Alert.alert('Error', 'Consecutive duplicate waypoints are not allowed');
return false;
default:
showSnackbar('Route status: ' + routeStatus);
Alert.alert('Error', 'Starting Guidance Error');
return false;
}
};
/**
* Handles the response from continueToNextDestination.
*
* Checks the route status (if available, i.e. on iOS) and stops guidance
* on failure. Returns the response for further processing.
*
* @param navigationController - The navigation controller instance.
* @param response - The response from continueToNextDestination.
* @returns true if navigation can continue, false if it was aborted.
*/
export const handleContinueToNextDestination = async (
navigationController: NavigationController,
response: ContinueToNextDestinationResponse
): Promise<boolean> => {
// If routeStatus is available (iOS), check for errors
if (response.routeStatus !== undefined) {
if (!handleRouteStatus(response.routeStatus)) {
await navigationController.stopGuidance();
return false;
}
}
if (response.waypoint === null) {
showSnackbar('No more waypoints remaining');
await navigationController.stopGuidance();
return false;
}
return true;
};