Geolocator.StatusChanged 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
// 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 类中的此事件。 Disabled 的 GeofenceMonitorStatus 等效于 DisabledPositionStatus - 这两者都表示应用无权访问位置。