无为清净楼资源网 Design By www.qnjia.com
在Windows8中,定位器不一定随时可用,所以我们在使用定位器时最好先检查一下定位器的状态。
状态可以从Geolocator中的属性LocationStatus获得。

定位器状态是枚举类型PositionStatus,共有6种状态:Ready、Initializing、NoData、Disabled、NotInitialized、NotAvailable。
另外,有时还需要不断检测定位器的状态,当定位器不可用时给用户友好的提示,或做出其它的动作。Geolocator中有一个事件StatusChanged专门用来监测定位器状态的改变。
下面来看代码,总共只有一张页面。
前台XAML代码如下

复制代码代码如下:
<Page
x:Class="Win8Location.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Win8Location"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button x:Name="btnCheckStatusChanged" Content="监测定位器状态" Click="btnCheckStatusChanged_Click"/>
<ScrollViewer>
<TextBlock x:Name="txtMsg" TextWrapping="Wrap" FontSize="20"/>
</ScrollViewer>
</StackPanel>
</Page>

后台cs代码如下

复制代码代码如下:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace Win8Location
{
public sealed partial class MainPage : Page
{
Geolocator geo = null;
public MainPage()
{
this.InitializeComponent();
}
private void btnCheckStatusChanged_Click(object sender, RoutedEventArgs e)
{
btnCheckStatusChanged.IsEnabled = false;
if (geo == null)
{
geo = new Geolocator();
}
txtMsg.Text = DateTime.Now.ToString() + ">定位器启动,状态为:" + geo.LocationStatus + "\n状态描述:" + GetDescription(geo.LocationStatus);
geo.StatusChanged += geo_StatusChanged;
}
async void geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
{
PositionStatus statu = args.Status;
string msg = "\n\n" + DateTime.Now.ToString() + ">定位器状态改变为:" + statu.ToString();
msg += "\n状态描述:" + GetDescription(statu);
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
txtMsg.Text += msg;
});
}
string GetDescription(PositionStatus statu)
{
string description = null;
switch (statu)
{
case PositionStatus.Ready:
description = "提供位置数据。";
break;
case PositionStatus.Initializing:
description = "位置提供程序正在初始化。如果 GPS 是位置数据源,并且视图中的 GPS 接收器没有所需的附属数目来获取准确的位置,则此为该状态。";
break;
case PositionStatus.NoData:
description = "没有来自任何位置提供程序的可用位置数据。在可从位置传感器获取数据之前,LocationStatus 将在应用程序调用 GetGeopositionAsync或注册 PositionChanged 事件的事件处理程序时具有此值。数据可用后,LocationStatus 转换为 Ready 状态。";
break;
case PositionStatus.Disabled:
description = "位置提供程序已禁用。此状态指示尚未被授予该用户访问位置的应用程序权限。";
break;
case PositionStatus.NotInitialized:
description = "检索位置的操作尚未初始化。如果应用程序尚未调用 GetGeopositionAsync,或为 PositionChanged 事件注册事件处理程序,则LocationStatus 可能具有此值。";
break;
case PositionStatus.NotAvailable:
description = "Windows 传感器和位置平台在此版本的 Windows 中不可用。";
break;
default:
description = "您的定位器太先进了,目前的技术无法得知其状态:)";
break;
}
return description;
}
}
}

运行截图如下:
Windows 8 地理位置定位以及定位器状态监测
标签:
地理位置,定位器

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?