GPS信号较弱时禁用功能

时间:2014-04-03 23:19:37

标签: c# windows-phone-8

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

1 个答案:

答案 0 :(得分:0)

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

这里有一个例子: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;
    }
}