The SendLocation
RPC gives you the ability to send a GPS location to the active navigation app on the module.
When using the SendLocation
RPC, you will not have access to any information about how the user interacted with this location, only if the request was successfully sent. The request will be handled by the module from that point on using the active navigation system.
The SendLocation
RPC is 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 send a location 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
).
UUID listenerId = sdlManager.getPermissionManager().addListener(Arrays.asList(new PermissionElement(FunctionID.SEND_LOCATION, null)), PermissionManager.PERMISSION_GROUP_TYPE_ANY, new OnPermissionChangeListener() { @Override public void onPermissionsChange(@NonNull Map<FunctionID, PermissionStatus> allowedPermissions, @NonNull int permissionGroupStatus) { if (permissionGroupStatus != PermissionManager.PERMISSION_GROUP_TYPE_ALL_ALLOWED) { // Your app does not have permission to send the `SendLocation` request for its current HMI level return; } // Your app has permission to send the `SendLocation` request for its current HMI level } });
Since some modules will not support sending a location, 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 sending a location, 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 sending a location 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 SendLocation
request.
private void isSendLocationSupported(final OnCapabilitySupportedListener capabilitySupportedListener) { // Check if the module has navigation capabilities if (!sdlManager.getSystemCapabilityManager().isCapabilitySupported(SystemCapabilityType.NAVIGATION)) { capabilitySupportedListener.onCapabilitySupported(false); return; } // Legacy modules (pre-RPC Spec v4.5) do not support system capabilities, so for versions less than 4.5 we will assume `SendLocation` is supported if `isCapabilitySupported()` returns true SdlMsgVersion sdlMsgVersion = sdlManager.getRegisterAppInterfaceResponse().getSdlMsgVersion(); if (sdlMsgVersion == null) { capabilitySupportedListener.onCapabilitySupported(true); return; } Version rpcSpecVersion = new Version(sdlMsgVersion); if (rpcSpecVersion.isNewerThan(new Version(4, 5, 0)) < 0) { capabilitySupportedListener.onCapabilitySupported(true); return; } // Retrieve the navigation capability sdlManager.getSystemCapabilityManager().getCapability(SystemCapabilityType.NAVIGATION, new OnSystemCapabilityListener() { @Override public void onCapabilityRetrieved(Object capability) { NavigationCapability navigationCapability = (NavigationCapability) capability; capabilitySupportedListener.onCapabilitySupported(navigationCapability != null ? navigationCapability.getSendLocationEnabled() : false); } @Override public void onError(String info) { capabilitySupportedListener.onError(info); } }, false); } public interface OnCapabilitySupportedListener { void onCapabilitySupported(Boolean supported); void onError(String info); }
To use the SendLocation
request, you must at minimum include the longitude and latitude of the location.
SendLocation sendLocation = new SendLocation() .setLatitudeDegrees(42.877737) .setLongitudeDegrees(-97.380967) .setLocationName("The Center") .setLocationDescription("Center of the United States"); OasisAddress address = new OasisAddress() .setSubThoroughfare("900") .setThoroughfare("Whiting Dr") .setLocality("Yankton") .setAdministrativeArea("SD") .setPostalCode("57078") .setCountryCode("US-SD") .setCountryName("United States"); sendLocation.setAddress(address); sendLocation.setOnRPCResponseListener(new OnRPCResponseListener() { @Override public void onResponse(int correlationId, RPCResponse response) { Result result = response.getResultCode(); if(result.equals(Result.SUCCESS)){ // `SendLocation` successfully sent }else if(result.equals(Result.INVALID_DATA)){ // `SendLocation` was rejected. The request contained invalid data }else if(result.equals(Result.DISALLOWED)){ // Your app is not allowed to use `SendLocation` } } }); sdlManager.sendRPC(sendLocation);
The SendLocation
request has three possible responses that you should expect:
SUCCESS
- Successfully sent.INVALID_DATA
- The request contains invalid data and was rejected.DISALLOWED
- Your app does not have permission to use the SendLocation
request.