Geolocator.StatusChanged | statuschanged event

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

Syntax


public event TypedEventHandler<Geolocator, StatusChangedEventArgs> StatusChanged

Event information

Delegate TypedEventHandler<Geolocator, StatusChangedEventArgs>

Remarks

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

Important  Call the RequestAccessAsync before accessing the user’s location. At that time, your app must be in the foreground and RequestAccessAsync must be called from the UI thread. Until the user grants your app permission to their location, your app can't access location data.

The GetGeopositionAsync method times out after 60 seconds, except when in Connected Standby. During Connected Standby, Geolocator objects can be instantiated but the Geolocator object will not find any sensors to aggregate and calls to GetGeopositionAsync will time out after 7 seconds. Upon time out, the StatusChanged event listeners will be called once with the NoData status, and the PositionChanged event listeners will never be called.

Examples

The following example shows how to handle the StatusChanged event.



loc = new Windows.Devices.Geolocation.Geolocator();

// Add event handlers for the statuschanged event.
loc.addEventListener("statuschanged", onStatusChanged);

// Handler for statusChanged event.        
function onStatusChanged(args) {
    var newStatus = args.status;

    document.getElementById('geolocatorStatus').innerHTML =
            getStatusString(newStatus);
}

// display an appropriate error message
function getStatusString(locStatus) {

    switch (locStatus) {
        case Windows.Devices.Geolocation.PositionStatus.ready:
            // Location data is available
            return "Location is available.";
            break;

        case Windows.Devices.Geolocation.PositionStatus.initializing:
            // This status indicates that a GPS is still acquiring a fix
            return "A GPS device is still initializing.";
            break;

        case Windows.Devices.Geolocation.PositionStatus.noData:
            // No location data is currently available
            return "Data from location services is currently unavailable.";
            break;

        case Windows.Devices.Geolocation.PositionStatus.disabled:
            // The app doesn't have permission to access location,
            // either because location has been turned off.
            return "Your location is currently turned off. " +
                 "Change your settings through the Settings charm " +
                 " to turn it back on.";
            break;

         case Windows.Devices.Geolocation.PositionStatus.notInitialized:
            // This status indicates that the app has not yet requested
            // location data by calling GetGeolocationAsync() or
            // registering an event handler for the positionChanged event.
            return "Location status is not initialized because " +
                "the app has not requested location data.";
            break;

         case Windows.Devices.Geolocation.PositionStatus.notAvailable:
             // Location is not available on this version of Windows
             return "You do not have the required location services " +
                 "present on your system.";
             break;

         default:
             return "Unknown status";

    }
}

Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Devices.Geolocation
Windows::Devices::Geolocation [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8

Minimum supported server

None supported

Minimum supported phone

Windows Phone 8

Namespace

Windows.Devices.Geolocation
Windows::Devices::Geolocation [C++]

Metadata

Windows.winmd

See also

Detect a user's location
Respond to location updates
Set up a geofence
Geolocator
StatusChangedEventArgs

 

 

Show:
© 2015 Microsoft