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)을 통해 해당 상태를 전달합니다. 이 메서드는 UI 스레드로부터 호출되지 않고 Dispatcher 개체가 UI 변경 사항을 호출합니다. 자세한 내용은 현재 위치 가져오기를 참조하세요.

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 개체를 사용하여 이벤트에 대한 정보에 액세스할 수 있습니다.

지오펜스를 사용하는 경우 GeofenceMonitorStatusChanged 이벤트를 사용하여 Geolocator 클래스에서 이 이벤트 대신 위치 권한의 변경 내용을 모니터링합니다. Disabled의 GeofenceMonitorStatusDisabledPositionStatus와 동일합니다. 둘 다 앱에 위치에 액세스할 수 있는 권한이 없음을 나타냅니다.

적용 대상

추가 정보