Weitere AWS-SDK-Beispiele sind im GitHub-Repository Beispiele für AWS Doc SDKs
BatchUpdateDevicePosition mit einem AWS-SDK verwenden
Die folgenden Code-Beispiele zeigen, wie BatchUpdateDevicePosition verwendet wird.
- Java
-
- SDK für Java 2.x
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Code-Beispiel-
einrichten und ausführen. /** * Updates the position of a device in the location tracking system. * * @param trackerName the name of the tracker associated with the device * @param deviceId the unique identifier of the device * @throws RuntimeException if an error occurs while updating the device position */ public CompletableFuture<BatchUpdateDevicePositionResponse> updateDevicePosition(String trackerName, String deviceId) { double latitude = 37.7749; // Example: San Francisco double longitude = -122.4194; DevicePositionUpdate positionUpdate = DevicePositionUpdate.builder() .deviceId(deviceId) .sampleTime(Instant.now()) // Timestamp of position update. .position(Arrays.asList(longitude, latitude)) // AWS requires [longitude, latitude] .build(); BatchUpdateDevicePositionRequest request = BatchUpdateDevicePositionRequest.builder() .trackerName(trackerName) .updates(positionUpdate) .build(); CompletableFuture<BatchUpdateDevicePositionResponse> futureResponse = getClient().batchUpdateDevicePosition(request); return futureResponse.whenComplete((response, exception) -> { if (exception != null) { Throwable cause = exception.getCause(); if (cause instanceof ResourceNotFoundException) { throw new CompletionException("The resource was not found: " + cause.getMessage(), cause); } else { throw new CompletionException("Error updating device position: " + exception.getMessage(), exception); } } }); }-
Weitere API-Informationen finden Sie unter BatchUpdateDevicePosition in der AWS SDK for Java 2.x-API-Referenz.
-
- JavaScript
-
- SDK für JavaScript (v3)
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Code-Beispiel-
einrichten und ausführen. import { fileURLToPath } from "node:url"; import { BatchUpdateDevicePositionCommand, LocationClient, ResourceNotFoundException, } from "@aws-sdk/client-location"; import data from "./inputs.json" with { type: "json" }; const region = "eu-west-1"; const locationClient = new LocationClient({ region: region }); const updateDevicePosParams = { TrackerName: `${data.inputs.trackerName}`, Updates: [ { DeviceId: `${data.inputs.deviceId}`, SampleTime: new Date(), Position: [-122.4194, 37.7749], }, ], }; export const main = async () => { try { const command = new BatchUpdateDevicePositionCommand(updateDevicePosParams); const response = await locationClient.send(command); //console.log("response ", response.Errors[0].Error); console.log( `Device with id ${data.inputs.deviceId} was successfully updated in the location tracking system. `, response, ); } catch (error) { console.log("error ", error); } };-
Weitere API-Informationen finden Sie unter BatchUpdateDevicePosition in der AWS SDK für JavaScript-API-Referenz.
-
- Kotlin
-
- SDK für Kotlin
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Code-Beispiel-
einrichten und ausführen. /** * Updates the position of a device in the location tracking system. * * @param trackerName the name of the tracker associated with the device * @param deviceId the unique identifier of the device */ suspend fun updateDevicePosition(trackerName: String, deviceId: String) { val latitude = 37.7749 val longitude = -122.4194 val positionUpdate = DevicePositionUpdate { this.deviceId = deviceId sampleTime = aws.smithy.kotlin.runtime.time.Instant.now() // Timestamp of position update. position = listOf(longitude, latitude) // AWS requires [longitude, latitude] } val request = BatchUpdateDevicePositionRequest { this.trackerName = trackerName updates = listOf(positionUpdate) } LocationClient.fromEnvironment { region = "us-east-1" }.use { client -> client.batchUpdateDevicePosition(request) } }-
Weitere API-Informationen finden Sie unter BatchUpdateDevicePosition
in der API-Referenz zum AWS SDK für Kotlin.
-