为Windows Phone 8.1创建位置状态更改事件的委托方法

时间:2015-09-26 06:33:27

标签: windows-phone-8.1 location

我目前正在使用Windows Phone 8.1 [RT]应用程序,我正在使用GeoLocation进行地图服务,我想要在设备位置打开/关闭时发生的事件,与用于互联网连接的NetworkStatusChangedEventHandler相同。 我为此创建了以下代码

 public static bool IsLocationOn
 {
        get
        {
            Geolocator locator = new Geolocator();

            if (locator.LocationStatus == PositionStatus.Disabled)
            {
                return false;
            }
            else
            {
                return true;
            }

        }
 }

但是我希望在整个应用程序中触发事件 谢谢

1 个答案:

答案 0 :(得分:0)

Geolocator有一个StatusChanged事件。从那里开始,只需订阅它。

locator.StatusChanged += Geolocator_StatusChanged;

private void Geolocator_StatusChanged(Geolocator locator, StatusChangedEventArgs e)
{
    // Whatever
}
相关问题