信息
您所需的主题如下所示。但此主题未包含在此库中。

Geolocator.StatusChanged | statuschanged Event

Geolocator 提供更新位置的功能发生更改时引发。

语法


function onStatusChanged(eventArgs) { /* 代码 */ }
 
// addEventListener syntax
geolocator.addEventListener("statuschanged", onStatusChanged);
geolocator.removeEventListener("statuschanged", onStatusChanged);
 
- or -

geolocator.onstatuschanged = onStatusChanged;


事件信息

委托 TypedEventHandler<Geolocator, StatusChangedEventArgs>

备注

您可以访问有关传递给事件处理程序的 StatusChangedEventArgs 对象的事件的信息。

当在联接的备用时,Geolocator 对象始终可以实例化,但 Geolocator 对象将不会找到任何传感器来聚合并调用 GetGeopositionAsync 在 7 秒后将超时,将不会调用 PositionChanged 事件侦听器,并且 StatusChanged 事件侦听器将以 NoData 状态一次调用。

示例

下面的示例演示如何处理 StatusChanged 事件。



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";

    }
}

要求

最低支持客户端

Windows 8

最低支持服务器

不支持“无”

最低支持电话

Windows Phone 8

命名空间

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

元数据

Windows.winmd

Capabilities

location
ID_CAP_LOCATION [Windows Phone]

另请参见

Geolocator
StatusChangedEventArgs

 

 

显示: