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 スレッドから呼び出されず、Dispatcher オブジェクトが 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 クラスからのこのイベントではなく、場所のアクセス許可の変更を監視します。 GeofenceMonitorStatus の Disabled は、DisabledPositionStatus と同じです。どちらも、アプリに場所へのアクセス許可がないことを示します。
適用対象
こちらもご覧ください
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示