Geolocator.StatusChanged Evento
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Generato quando la capacità del Geolocator di fornire modifiche alla posizione aggiornate.
// Register
event_token StatusChanged(TypedEventHandler<Geolocator, StatusChangedEventArgs const&> const& handler) const;
// Revoke with event_token
void StatusChanged(event_token const* cookie) const;
// Revoke with event_revoker
Geolocator::StatusChanged_revoker StatusChanged(auto_revoke_t, TypedEventHandler<Geolocator, StatusChangedEventArgs const&> const& handler) const;
public event TypedEventHandler<Geolocator,StatusChangedEventArgs> StatusChanged;
function onStatusChanged(eventArgs) { /* Your code */ }
geolocator.addEventListener("statuschanged", onStatusChanged);
geolocator.removeEventListener("statuschanged", onStatusChanged);
- or -
geolocator.onstatuschanged = onStatusChanged;
Public Custom Event StatusChanged As TypedEventHandler(Of Geolocator, StatusChangedEventArgs)
Tipo evento
Requisiti Windows
Funzionalità dell'app |
location
ID_CAP_LOCATION [Windows Phone]
|
Esempio
Questo esempio di codice illustra come viene gestito l'evento StatusChanged. L’oggetto Geolocator attiva l’evento StatusChanged per indicare che le impostazioni di posizione dell’utente sono cambiate. L’evento passa lo stato corrispondente tramite la proprietà Status dell’argomento (di tipo PositionStatus). Tieni presente che questo metodo non viene chiamato dal thread dell'interfaccia utente e che l'oggetto Dispatcher richiama le modifiche dell'interfaccia utente. Per altre info, vedi Ottenere la posizione corrente.
using Windows.UI.Core;
...
async private void OnStatusChanged(Geolocator sender, StatusChangedEventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
// Show the location setting message only if status is disabled.
LocationDisabledMessage.Visibility = Visibility.Collapsed;
switch (e.Status)
{
case PositionStatus.Ready:
// Location platform is providing valid data.
// notify user: Location platform is ready
break;
case PositionStatus.Initializing:
// Location platform is attempting to acquire a fix.
// notify user: Location platform is attempting to obtain a position
break;
case PositionStatus.NoData:
// Location platform could not obtain location data.
// notify user: Not able to determine the location
break;
case PositionStatus.Disabled:
// The permission to access location data is denied by the user or other policies.
// notify user: Access to location is denied
// Clear cached location data if any
break;
case PositionStatus.NotInitialized:
// The location platform is not initialized. This indicates that the application
// has not made a request for location data.
// notify user: No request for location is made yet
break;
case PositionStatus.NotAvailable:
// The location platform is not available on this version of the OS.
// notify user: Location is not available on this version of the OS
break;
default:
// unknown result
break;
}
});
}
Commenti
È possibile accedere alle informazioni sull'evento con l'oggetto StatusChangedEventArgs passato al gestore eventi.
Quando si usa un geofence, usare l'evento StatusChanged di GeofenceMonitor per monitorare le modifiche nelle autorizzazioni di posizione anziché questo evento dalla classe Geolocator. Un GeofenceMonitorStatus di Disabilitato equivale a un Valore PositionStatus disabilitato, entrambi indicano che l'app non dispone dell'autorizzazione per accedere alla posizione.
Si applica a
Vedi anche
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per