Controlla la disponibilità del servizio VPS nella posizione attuale del dispositivo
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
L'API Geospatial utilizza una combinazione di dati VPS e GPS per generare pose geospaziali ad alta precisione. L'API può essere utilizzata in qualsiasi luogo in cui il dispositivo è in grado di determinare la propria posizione:
- Nelle aree con scarsa precisione del GPS, come spazi interni ed ambienti urbani densi, l'API si baserà sulla copertura VPS per generare pose ad alta precisione.
- In ambienti esterni con poche o nessuna ostruzione sopraelevata, l'API Geospatial potrebbe essere in grado di utilizzare i dati sulla posizione GPS disponibili per generare pose geospaziali con elevata precisione.
Puoi determinare la disponibilità del VPS in una determinata posizione orizzontale prima dell'inizio della sessione AR e utilizzarla per creare esperienze più specifiche, ad esempio per mostrare un pulsante "Accedi all'AR" solo quando il VPS è disponibile.
Attiva l'API ARCore
L'app deve attivare l'API ARCore per controllare la disponibilità del VPS.
Una volta attivata l'API ARCore, puoi controllare la disponibilità del VPS senza:
Verificare la disponibilità del VPS nell'app
L'API Geospatial può essere utilizzata in qualsiasi luogo in cui il dispositivo è in grado di determinare la propria posizione. Se la tua esperienza AR dipende dalla copertura del VPS, puoi utilizzare Session.checkVpsAvailabilityAsync()
per ottenere un VpsAvailabilityFuture
, un'attività asincrona che controlla la disponibilità del VPS in una determinata posizione orizzontale.
Una volta ottenuto VpsAvailabilityFuture
, puoi ottenere il risultato tramite polling o tramite un callback.
Effettua il sondaggio sul risultato
Utilizza Future.getState()
per ottenere lo stato del Future
. Esistono tre stati diversi:
Puoi continuare a selezionare Future.getState()
finché l'attività non è completata.
Java
// Obtain a VpsAvailabilityFuture and store it somewhere.
VpsAvailabilityFuture future = session.checkVpsAvailabilityAsync(latitude, longitude, null);
// Poll VpsAvailabilityFuture later, for example, in a render loop.
if (future.getState() == FutureState.DONE) {
switch (future.getResult()) {
case AVAILABLE:
// VPS is available at this location.
break;
case UNAVAILABLE:
// VPS is unavailable at this location.
break;
case ERROR_NETWORK_CONNECTION:
// The external service could not be reached due to a network connection error.
break;
// Handle other error states, e.g. ERROR_RESOURCE_EXHAUSTED, ERROR_INTERNAL, ...
}
}
Kotlin
// Obtain a VpsAvailabilityFuture and store it somewhere.
val future = session.checkVpsAvailabilityAsync(latitude, longitude, null)
// Poll VpsAvailabilityFuture later, for example, in a render loop.
if (future.state == FutureState.DONE) {
when (future.result) {
VpsAvailability.AVAILABLE -> {
// VPS is available at this location.
}
VpsAvailability.UNAVAILABLE -> {
// VPS is unavailable at this location.
}
VpsAvailability.ERROR_NETWORK_CONNECTION -> {
// The external service could not be reached due to a network connection error.
}
else -> {
TODO("Handle other error states, e.g. ERROR_RESOURCE_EXHAUSTED, ERROR_INTERNAL, ...")
}
}
}
Ottenere il risultato tramite una chiamata di ritorno
Puoi anche ottenere il risultato di un Future
tramite un callback. Utilizza Session.checkVpsAvailabilityAsync()
e fornisci un callback
. Questo callback
verrà chiamato nel thread principale subito dopo che Future
avrà lo stato DONE
.
Java
session.checkVpsAvailabilityAsync(
latitude,
longitude,
result -> {
// Callback is called on the Main thread.
switch (result) {
// Handle the VpsAvailability result as shown above.
// For example, show UI that enables your AR view.
}
});
Kotlin
session.checkVpsAvailabilityAsync(latitude, longitude) { result ->
// Callback is called on the Main thread.
// Handle the VpsAvailability result as shown above.
// For example, show UI that enables your AR view.
TODO("Handle VpsAvailability " + result)
}
Annullare l'Future
Usa Future.cancel()
per tentare di annullare l'Future
. A causa del parallelismo dei thread, è possibile che il tentativo di annullamento non vada a buon fine.
Future.cancel()
restituisce true
se il tentativo è riuscito e false
in caso contrario.
Utilizzare l'API Geospatial senza copertura VPS
L'API Geospatial può essere utilizzata anche nelle aree che non hanno copertura VPS. In ambienti esterni con poche o nessuna ostruzione sopraelevata, il GPS potrebbe essere sufficiente per generare una posa con elevata precisione.
Passaggi successivi
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 2025-07-26 UTC."],[[["\u003cp\u003eThe Geospatial API leverages VPS and GPS data to create precise AR experiences, adapting to environments with varying location accuracy.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can proactively check VPS availability before initiating AR sessions, enabling context-aware features like conditional AR activation buttons.\u003c/p\u003e\n"],["\u003cp\u003eThe API offers flexible methods for obtaining VPS availability results, including polling and callbacks, accommodating different development approaches.\u003c/p\u003e\n"],["\u003cp\u003eEven without VPS coverage, the Geospatial API can function in outdoor settings with clear GPS signals, ensuring broader usability.\u003c/p\u003e\n"],["\u003cp\u003eAfter confirming VPS availability or suitable GPS conditions, developers can proceed to obtain the device's Geospatial pose and build immersive AR experiences grounded in real-world locations.\u003c/p\u003e\n"]]],[],null,["# Check VPS availability at the device's current location\n\n\u003cbr /\u003e\n\nThe Geospatial API uses a combination of [VPS](/ar/develop/geospatial#global_localization_with_vps) and GPS data to generate high-accuracy Geospatial poses. The API can be used in any place where the device is able to determine its location:\n\n- In areas with low GPS accuracy, such as indoor spaces and dense urban environments, the API will rely on VPS coverage to generate high-accuracy poses.\n- In outdoor environments with few or no overhead obstructions, the Geospatial API may be able to use available GPS location data to generate Geospatial poses with high accuracy.\n\nYou can determine VPS availability at a given horizontal position before the AR session starts and use it to create more specific experiences --- for example, to present an \"Enter AR\" button only when VPS is available.\n\nEnable the ARCore API\n---------------------\n\nYour app must enable the [ARCore API](/ar/develop/java/geospatial/enable#enable_the_arcore_api) to check VPS availability.\n\nOnce the ARCore API is enabled, you can check VPS availability without:\n\n- A current running [`Session`](/ar/reference/java/com/google/ar/core/Session) (before calling [`Session.resume()`](/ar/reference/java/com/google/ar/core/Session#resume-)).\n- Setting a [`GeospatialMode`](/ar/reference/java/com/google/ar/core/Config.GeospatialMode).\n\nCheck VPS availability in your app\n----------------------------------\n\nThe Geospatial API can be used in any place where the device is able to determine its location. If your AR experience hinges on VPS coverage, you can use [`Session.checkVpsAvailabilityAsync()`](/ar/reference/java/com/google/ar/core/Session#checkVpsAvailabilityAsync-latitude-longitude-callback) to obtain a [`VpsAvailabilityFuture`](/ar/reference/java/com/google/ar/core/VpsAvailabilityFuture), an asynchronous task that checks the VPS availability at a given horizontal position.\n\nOnce you have the [`VpsAvailabilityFuture`](/ar/reference/java/com/google/ar/core/VpsAvailabilityFuture), you can obtain its result by polling or through a callback.\n\n\n### Poll the result\n\nUse [`Future.getState()`](/ar/reference/java/com/google/ar/core/Future#getState-) to obtain the state of the `Future`. There are three different states:\n\n- [`PENDING`](/ar/reference/java/com/google/ar/core/FutureState#done): The operation is not yet complete, so no result is known.\n- [`CANCELLED`](/ar/reference/java/com/google/ar/core/FutureState#done): The operation has been cancelled by [`Future.cancel()`](/ar/reference/java/com/google/ar/core/Future#cancel-). Any registered callback will never be called.\n- [`DONE`](/ar/reference/java/com/google/ar/core/FutureState#done): The operation is complete. Use [`VpsAvailabilityFuture.getResult()`](/ar/reference/java/com/google/ar/core/VpsAvailabilityFuture#getResult()) to obtain the result.\n\nYou may continue checking [`Future.getState()`](/ar/reference/java/com/google/ar/core/Future#getState-) until the task is complete. \n\n### Java\n\n```java\n// Obtain a VpsAvailabilityFuture and store it somewhere.\nVpsAvailabilityFuture future = session.checkVpsAvailabilityAsync(latitude, longitude, null);\n\n// Poll VpsAvailabilityFuture later, for example, in a render loop.\nif (future.getState() == FutureState.DONE) {\n switch (future.getResult()) {\n case AVAILABLE:\n // VPS is available at this location.\n break;\n case UNAVAILABLE:\n // VPS is unavailable at this location.\n break;\n case ERROR_NETWORK_CONNECTION:\n // The external service could not be reached due to a network connection error.\n break;\n\n // Handle other error states, e.g. ERROR_RESOURCE_EXHAUSTED, ERROR_INTERNAL, ...\n }\n}\n```\n\n### Kotlin\n\n```kotlin\n// Obtain a VpsAvailabilityFuture and store it somewhere.\nval future = session.checkVpsAvailabilityAsync(latitude, longitude, null)\n\n// Poll VpsAvailabilityFuture later, for example, in a render loop.\nif (future.state == FutureState.DONE) {\n when (future.result) {\n VpsAvailability.AVAILABLE -\u003e {\n // VPS is available at this location.\n }\n VpsAvailability.UNAVAILABLE -\u003e {\n // VPS is unavailable at this location.\n }\n VpsAvailability.ERROR_NETWORK_CONNECTION -\u003e {\n // The external service could not be reached due to a network connection error.\n }\n else -\u003e {\n TODO(\"Handle other error states, e.g. ERROR_RESOURCE_EXHAUSTED, ERROR_INTERNAL, ...\")\n }\n }\n}\n```\n\n### Obtain the result through a callback\n\nYou can also obtain the result of a `Future` through a callback. Use [`Session.checkVpsAvailabilityAsync()`](/ar/reference/java/com/google/ar/core/Session#checkVpsAvailabilityAsync-latitude-longitude-callback) and supply a `callback`. This `callback` will be called on the Main thread soon after the `Future` has state [`DONE`](/ar/reference/java/com/google/ar/core/FutureState#done). \n\n### Java\n\n```java\nsession.checkVpsAvailabilityAsync(\n latitude,\n longitude,\n result -\u003e {\n // Callback is called on the Main thread.\n switch (result) {\n // Handle the VpsAvailability result as shown above.\n // For example, show UI that enables your AR view.\n }\n });\n```\n\n### Kotlin\n\n```kotlin\nsession.checkVpsAvailabilityAsync(latitude, longitude) { result -\u003e\n // Callback is called on the Main thread.\n\n // Handle the VpsAvailability result as shown above.\n // For example, show UI that enables your AR view.\n TODO(\"Handle VpsAvailability \" + result)\n}\n```\n\nCancel the `Future`\n-------------------\n\nUse [`Future.cancel()`](/ar/reference/java/com/google/ar/core/Future#cancel-) to attempt to cancel the `Future`. Due to thread parallelism, it may be possible that your cancel attempt does not actually succeed.\n\n`Future.cancel()` returns `true` if this attempt was successful, and `false` otherwise.\n\nUse the Geospatial API without VPS coverage\n-------------------------------------------\n\nThe Geospatial API can also be used in areas that do not have VPS coverage. In outdoor environments with few or no overhead obstructions, GPS may be sufficient to generate a pose with high accuracy.\n\nWhat's next\n-----------\n\n- [Obtain the device camera's Geospatial pose](/ar/develop/java/geospatial/obtain-device-pose) to determine the exact location of the user's device in the real world."]]