Geolocator.StatusChanged Событие

Определение

Возникает при изменении возможности геолокатора предоставлять обновленное расположение.

// 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) 

Тип события

Требования к Windows

Возможности приложения
location ID_CAP_LOCATION [Windows Phone]

Примеры

В этом примере кода показано, как обрабатывается событие StatusChanged. Объект Geolocator запускает событие StatusChanged для указания того, что местоположение пользователя изменилось. Это событие передает данные о соответствующем состоянии через свойство аргумента Status (типа PositionStatus). Обратите внимание, что этот метод не вызывается из потока пользовательского интерфейса и объект Dispatcher фактически вызывает изменения пользовательского интерфейса. Дополнительные сведения см. в статье Получение сведений о текущем местоположении.

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;
        }
    });
}

Комментарии

Доступ к сведениям о событии можно получить с помощью объекта StatusChangedEventArgs , передаваемого обработчику событий.

При использовании геозоны используйте событие StatusChangedgeofenceMonitor, чтобы отслеживать изменения разрешений расположения вместо этого события из класса Geolocator. Значение GeofenceMonitorStatusотключено эквивалентно параметру DisabledPositionStatus. Оба указывают, что приложение не имеет разрешения на доступ к расположению.

Применяется к

См. также раздел