The GetWayPoints
and SubscribeWayPoints
RPCs are designed to allow you to get the navigation destination(s) from the active navigation app when the user has activated in-car navigation.
Both the GetWayPoints
and SubscribeWayPoints
RPCs are restricted by most OEMs. As a result, a module may reject your request if your app does not have the correct permissions. Your SDL app may also be restricted to only being allowed to get waypoints when your app is open (i.e. the hmiLevel
is non-NONE
) or when it is the currently active app (i.e. the hmiLevel
is FULL
).
const permissionElements = []; permissionElements.push(new SDL.manager.permission.PermissionElement(SDL.rpc.enums.FunctionID.GetWayPoints, null)); permissionElements.push(new SDL.manager.permission.PermissionElement(SDL.rpc.enums.FunctionID.SubscribeWayPoints, null)); const listenerId = sdlManager.getPermissionManager().addListener(permissionElements, SDL.manager.permission.enums.PermissionGroupType.ANY, function (allowedPermissions, permissionGroupStatus) { if (allowedPermissions[SDL.rpc.enums.FunctionID.GetWayPoints].getIsRpcAllowed()) { // Your app has permission to send the `GetWayPoints` request for its current HMI level } else { // Your app does not have permission to send the `GetWayPoints` request for its current HMI level } if (allowedPermissions[SDL.rpc.enums.FunctionID.SubscribeWayPoints].getIsRpcAllowed()) { // Your app has permission to send the `SubscribeWayPoints` request for its current HMI level } else { // Your app does not have permission to send the `SubscribeWayPoints` request for its current HMI level } });
Since some modules will not support getting waypoints, you should check if the module supports this feature before trying to use it. Once you have successfully connected to the module, you can check the module's capabilities via the sdlManager.getSystemCapabilityManager()
as shown in the example below. Please note that you only need to check once if the module supports getting waypoints, however you must wait to perform this check until you know that the SDL app has been opened (i.e. the hmiLevel
is non-NONE
).
If you discover that the module does not support getting navigation waypoints or that your app does not have the right permissions, you should disable any buttons, voice commands, menu items, etc. in your app that would send the GetWayPoints
or SubscribeWayPoints
requests.
async function isGetWaypointsSupported() { // Check if the module has navigation capabilities if (!sdlManager.getSystemCapabilityManager().isCapabilitySupported(SDL.rpc.enums.SystemCapabilityType.NAVIGATION)) { return false; } // Legacy modules (pre-RPC Spec v4.5) do not support system capabilities, so for versions less than 4.5 we will assume `GetWayPoints` and `SubscribeWayPoints` are supported if `isCapabilitySupported` returns true let sdlMsgVersion = sdlManager.getRegisterAppInterfaceResponse().getSdlMsgVersion(); if (sdlMsgVersion == null) { return true; } let rpcSpecVersion = new SDL.util.Version(sdlMsgVersion.getMajorVersion(), sdlMsgVersion.getMinorVersion(), sdlMsgVersion.getPatchVersion()); if (rpcSpecVersion.isNewerThan(new SDL.util.Version(4, 5, 0)) < 0) { return true; } // Retrieve the navigation capability let isNavigationSupported = false; const navCapability = await sdlManager.getSystemCapabilityManager().updateCapability(SDL.rpc.enums.SystemCapabilityType.NAVIGATION) .catch(error => { throw error; }); if (navCapability !== null) { isNavigationSupported = navCapability.getGetWayPointsEnabled(); } return isNavigationSupported; }
To subscribe to the navigation waypoints, you will have to set up your callback for whenever the waypoints are updated, then send the SubscribeWayPoints
RPC.
// Create this method to receive the subscription callback sdlManager.addRpcListener(SDL.rpc.enums.FunctionID.OnWayPointChange, (onWayPointChangeNotification) => { // Use the waypoint data }); // After SDL has started your connection, at whatever point you want to subscribe, send the subscribe RPC const subscribeWayPoints = new SDL.rpc.messages.SubscribeWayPoints(); // sdl_javascript_suite v1.1+ const response = await sdlManager.sendRpcResolve(subscribeWayPoints); if (response.getSuccess()) { // You are now subscribed! } else { // Handle the errors } // thrown exceptions should be caught by a parent function via .catch() // Pre sdl_javascript_suite v1.1 const response = await sdlManager.sendRpc(subscribeWayPoints).catch(error => error); if (response.getSuccess()) { // You are now subscribed } else { // Handle the errors }
To unsubscribe from waypoint data, you must send the UnsubscribeWayPoints
RPC.
// sdl_javascript_suite v1.1+ const unsubscribeWayPoints = new SDL.rpc.messages.UnsubscribeWayPoints(); const response = await sdlManager.sendRpcResolve(unsubscribeWayPoints); if (response.getSuccess()) { // You are now unsubscribed! } else { // Handle the errors } // thrown exceptions should be caught by a parent function via .catch() // Pre sdl_javascript_suite v1.1 const unsubscribeWayPoints = new SDL.rpc.messages.UnsubscribeWayPoints(); const response = await sdlManager.sendRpc(unsubscribeWayPoints).catch(error => error); if (response.getSuccess()) { // You are now unsubscribed } else { // Handle the errors }
If you only need waypoint data once without an ongoing subscription, you can use GetWayPoints
instead of SubscribeWayPoints
.
// sdl_javascript_suite v1.1+ const getWayPoints = new SDL.rpc.messages.GetWayPoints(); const response = await sdlManager.sendRpcResolve(getWayPoints); if (response.getSuccess()) { // Use the waypoint information } else { // Handle the errors } // thrown exceptions should be caught by a parent function via .catch() // Pre sdl_javascript_suite v1.1 const getWayPoints = new SDL.rpc.messages.GetWayPoints(); const response = await sdlManager.sendRpc(getWayPoints).catch(error => error); if (response.getSuccess()) { // Use the waypoint data } else { // Handle the errors }