2014-04-03 57 views
1

我正在開發一個WP8應用程序,我想禁用某些功能,直到手機找不到我的位置。 有沒有辦法做到這一點?GPS信號弱時禁用功能

回答

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