Share via


Geolocator.StatusChanged Event

Definition

Raised when the ability of the Geolocator to provide updated ___location changes.

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

Event Type

Windows requirements

App capabilities
___location ID_CAP_LOCATION [Windows Phone]

Examples

This code example demonstrates how the StatusChanged event is handled. The Geolocator object triggers the StatusChanged event to indicate that the user's ___location settings changed. That event passes the corresponding status via the argument's Status property (of type PositionStatus). Note that this method is not called from the UI thread and the Dispatcher object invokes the UI changes. For more info, see Get current ___location.

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

Remarks

You can access information about the event with the StatusChangedEventArgs object that is passed to your event handler.

When using a geofence, use the GeofenceMonitor's StatusChanged event to monitor changes in ___location permissions instead of this event from the Geolocator class. A GeofenceMonitorStatus of Disabled is equivalent to a Disabled PositionStatus - both indicate that the app does not have permission to access ___location.

Applies to

See also