Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzare DeleteGeofenceCollection con un SDK AWS
Gli esempi di codice seguenti mostrano come utilizzare DeleteGeofenceCollection.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- Java
-
- SDK per Java 2.x
-
/**
* Deletes a geofence collection asynchronously.
*
* @param collectionName the name of the geofence collection to be deleted
* @return a {@link CompletableFuture} that completes when the geofence collection has been deleted
*/
public CompletableFuture<Void> deleteGeofenceCollectionAsync(String collectionName) {
DeleteGeofenceCollectionRequest collectionRequest = DeleteGeofenceCollectionRequest.builder()
.collectionName(collectionName)
.build();
return getClient().deleteGeofenceCollection(collectionRequest)
.whenComplete((response, exception) -> {
if (exception != null) {
Throwable cause = exception.getCause();
if (cause instanceof ResourceNotFoundException) {
throw new CompletionException("The requested geofence collection was not found.", cause);
}
throw new CompletionException("Failed to delete geofence collection: " + exception.getMessage(), exception);
}
logger.info("The geofence collection {} was deleted.", collectionName);
})
.thenApply(response -> null);
}
- JavaScript
-
- SDK per JavaScript (v3)
-
import { fileURLToPath } from "node:url";
import {
DeleteGeofenceCollectionCommand,
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 deleteGeofenceCollParams = {
CollectionName: `${data.inputs.collectionName}`,
};
const locationClient = new LocationClient({ region: region });
try {
const command = new DeleteGeofenceCollectionCommand(
deleteGeofenceCollParams,
);
const response = await locationClient.send(command);
console.log("Collection deleted.");
} catch (caught) {
if (caught instanceof ResourceNotFoundException) {
console.error(
`${data.inputs.collectionName} Geofence collection not found.`,
);
return;
}
}
};
- Kotlin
-
- SDK per Kotlin
-
/**
* Deletes a geofence collection.
*
* @param collectionName the name of the geofence collection to be deleted
* @return a {@link CompletableFuture} that completes when the geofence collection has been deleted
*/
suspend fun deleteGeofenceCollection(collectionName: String) {
val collectionRequest = DeleteGeofenceCollectionRequest {
this.collectionName = collectionName
}
LocationClient.fromEnvironment { region = "us-east-1" }.use { client ->
client.deleteGeofenceCollection(collectionRequest)
println("The geofence collection $collectionName was deleted.")
}
}