当GPS信号较弱时禁用功能

本文关键字:功能 GPS 信号 | 更新日期: 2023-09-27 17:56:35

我正在开发一个WP8应用程序,我想禁用某些功能,直到手机找不到我的位置。有什么办法可以做到这一点吗?

当GPS信号较弱时禁用功能

从禁用它开始,然后询问当前位置,当它的状态发生变化时,启用你的东西?

这里有一个例子:http://msdn.microsoft.com/en-US/library/WindowsPhone/Develop/FF431782(v=vs.105).aspx

// Event handler for the GeoCoordinateWatcher.StatusChanged event.
void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
    switch (e.Status)
    {
        case GeoPositionStatus.Disabled:
            // The Location Service is disabled or unsupported.
            // Check to see whether the user has disabled the Location Service.
            if (watcher.Permission == GeoPositionPermission.Denied)
            {
                // The user has disabled the Location Service on their device.
                statusTextBlock.Text = "you have this application access to location.";
            }
            else
            {
                statusTextBlock.Text = "location is not functioning on this device";
            }
            break;
        case GeoPositionStatus.Initializing:
            // The Location Service is initializing.
            // Disable the Start Location button.
            startLocationButton.IsEnabled = false;
            break;
        case GeoPositionStatus.NoData:
            // The Location Service is working, but it cannot get location data.
            // Alert the user and enable the Stop Location button.
            statusTextBlock.Text = "location data is not available.";
            stopLocationButton.IsEnabled = true;
            break;
        case GeoPositionStatus.Ready:
            // The Location Service is working and is receiving location data.
            // Show the current position and enable the Stop Location button.
            statusTextBlock.Text = "location data is available.";
            stopLocationButton.IsEnabled = true;
            break;
    }
}