Geolocator.StatusChanged 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當 Geolocator 提供更新的位置變更時引發。
// Register
event_token StatusChanged(TypedEventHandler<Geolocator, StatusChangedEventArgs const&> const& handler) const;
// Revoke with event_token
void StatusChanged(event_token const* cookie) const;
// Revoke with event_revoker
Geolocator::StatusChanged_revoker StatusChanged(auto_revoke_t, TypedEventHandler<Geolocator, StatusChangedEventArgs const&> const& handler) const;
public event TypedEventHandler<Geolocator,StatusChangedEventArgs> StatusChanged;
function onStatusChanged(eventArgs) { /* Your code */ }
geolocator.addEventListener("statuschanged", onStatusChanged);
geolocator.removeEventListener("statuschanged", onStatusChanged);
- or -
geolocator.onstatuschanged = onStatusChanged;
Public Custom Event StatusChanged As TypedEventHandler(Of Geolocator, StatusChangedEventArgs)
事件類型
Windows 需求
應用程式功能 |
location
ID_CAP_LOCATION [Windows Phone]
|
範例
此程式代碼範例示範如何處理 StatusChanged 事件。 Geolocator 物件會觸發 StatusChanged 事件,指出使用者的位置設定已變更。 該事件會透過自變數的 Status 屬性傳遞對應狀態(類型為 PositionStatus)。 請注意,這個方法不會從UI線程呼叫,而且 發送器 物件會叫用UI變更。 如需詳細資訊,請參閱 取得目前的位置。
using Windows.UI.Core;
...
async private void OnStatusChanged(Geolocator sender, StatusChangedEventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
// Show the location setting message only if status is disabled.
LocationDisabledMessage.Visibility = Visibility.Collapsed;
switch (e.Status)
{
case PositionStatus.Ready:
// Location platform is providing valid data.
// notify user: Location platform is ready
break;
case PositionStatus.Initializing:
// Location platform is attempting to acquire a fix.
// notify user: Location platform is attempting to obtain a position
break;
case PositionStatus.NoData:
// Location platform could not obtain location data.
// notify user: Not able to determine the location
break;
case PositionStatus.Disabled:
// The permission to access location data is denied by the user or other policies.
// notify user: Access to location is denied
// Clear cached location data if any
break;
case PositionStatus.NotInitialized:
// The location platform is not initialized. This indicates that the application
// has not made a request for location data.
// notify user: No request for location is made yet
break;
case PositionStatus.NotAvailable:
// The location platform is not available on this version of the OS.
// notify user: Location is not available on this version of the OS
break;
default:
// unknown result
break;
}
});
}
備註
您可以使用傳遞至事件處理程式的 StatusChangedEventArgs 物件,存取事件的相關信息。
使用地理柵欄時,請使用 GeofenceMonitor的 StatusChanged 事件來監視位置許可權的變更,而不是來自 Geolocator 類別的這個事件。 GeofenceMonitorStatusDisabled 相當於 DisabledPositionStatus - 兩者都表示應用程式沒有存取位置的許可權。