Hay más ejemplos de AWS SDK disponibles en el repositorio de GitHub de ejemplos de AWS SDK de documentos
Cómo utilizar GetDevicePosition con un AWS SDK
Los siguientes ejemplos de código muestran cómo utilizar GetDevicePosition.
- Java
-
- SDK para Java 2.x
-
nota
Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS
. /** * Retrieves the position of a device using the provided LocationClient. * * @param trackerName The name of the tracker associated with the device. * @param deviceId The ID of the device to retrieve the position for. * @throws RuntimeException If there is an error fetching the device position. */ public CompletableFuture<GetDevicePositionResponse> getDevicePosition(String trackerName, String deviceId) { GetDevicePositionRequest request = GetDevicePositionRequest.builder() .trackerName(trackerName) .deviceId(deviceId) .build(); return getClient().getDevicePosition(request) .whenComplete((response, exception) -> { if (exception != null) { Throwable cause = exception.getCause(); if (cause instanceof ResourceNotFoundException) { throw new CompletionException("The AWS resource was not found: " + cause.getMessage(), cause); } throw new CompletionException("Error fetching device position: " + exception.getMessage(), exception); } }); }-
Para obtener información sobre la API, consulte GetDevicePosition en la Referencia de la API de AWS SDK for Java 2.x.
-
- JavaScript
-
- SDK para JavaScript (v3)
-
nota
Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS
. import { fileURLToPath } from "node:url"; import { GetDevicePositionCommand, LocationClient, ResourceNotFoundException, } from "@aws-sdk/client-location"; import data from "./inputs.json" with { type: "json" }; const region = "eu-west-1"; export const main = async () => { const locationClient = new LocationClient({ region: region }); const deviceId = `${data.inputs.deviceId}`; const trackerName = `${data.inputs.trackerName}`; const devicePositionParams = { DeviceId: deviceId, TrackerName: trackerName, }; try { const command = new GetDevicePositionCommand(devicePositionParams); const response = await locationClient.send(command); //state.position = response.position; console.log("Successfully fetched device position: ", response); } catch (error) { console.log("Error ", error); /* if (caught instanceof ResourceNotFoundException) { console.error( `"The resource was not found: ${caught.message} \n Exiting program.`, ); } else { `An unexpected error error occurred: ${caught.message} \n Exiting program.`; } return;*/ } };-
Para obtener información sobre la API, consulte GetDevicePosition en la Referencia de la API de AWS SDK para JavaScript.
-
- Kotlin
-
- SDK para Kotlin
-
nota
Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS
. /** * Retrieves the position of a device using the provided LocationClient. * * @param trackerName The name of the tracker associated with the device. * @param deviceId The ID of the device to retrieve the position for. */ suspend fun getDevicePosition(trackerName: String, deviceId: String): GetDevicePositionResponse { val request = GetDevicePositionRequest { this.trackerName = trackerName this.deviceId = deviceId } LocationClient.fromEnvironment { region = "us-east-1" }.use { client -> return client.getDevicePosition(request) } }-
Para obtener información sobre la API, consulte GetDevicePosition
en la Referencia de la API de AWS SDK para Kotlin.
-