??Windows Phone 环境中模??GPS 位置信息

日期:2016/6/24 16:43:00 来源:本网整理 阅读:0
http://www.eugenedotnet.com/2011/11/simulating-gps-position-changes-using-reactive-extensions-in-windows-phone-environment/

[1].[代码] [WPF/SliverLight]代码 跳至 [1]

private readonly GeoCoordinateWatcher _gcw = new GeoCoordinateWatcher();
 
private readonly Random _random = new Random();
 
public GpsSamplePage()
{
    InitializeComponent();
 
    bool isSimulation = true;
    if (!isSimulation)
    {
        _gcw.PositionChanged += (s, e) => GcwPositionChanged(e);
        _gcw.Start();
    }
    else
    {
        Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(4))
        .Select(x =>
            new GeoPositionChangedEventArgs<GeoCoordinate>(
                new GeoPosition<GeoCoordinate>(DateTime.Now,
                    new GeoCoordinate()
                        {
                            // -90 <= latitude <= 90
                            Latitude = (_random.NextDouble() * 180.0) - 90.0,
                            // -180 <= longitude <= 180
                            Longitude = (_random.NextDouble() * 360.0) - 180.0
                        }
 
                ))).ObserveOnDispatcher().Subscribe(GcwPositionChanged);
    }
}
 
void GcwPositionChanged(GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    Dispatcher.BeginInvoke(() =>
    {
        // thread safe
        tbLatitude.Text = e.Position.Location.Latitude.ToString();
        tbLongitude.Text = e.Position.Location.Longitude.ToString();
    });
}

  • 本文相关:
  • Windows Phone 7 下的 RSS 阅读??/a>[代码]
    红薯
  • 做一??Windows Phone GPS 开关设置界??/a>[代码]
    鉴客
  • 通过WebClient来获取网络内??/a>[代码]
    鉴客
  • WP7上HttpWebRequest的用??/a>[代码]
    鉴客
  • ??WP7 中使??SaveContactTask 保存联系??/a>[代码]
    红薯
  • 使用 SocketEx 编写 Windows Phone 平台??TCP 客户??/a>[代码]
    红薯
  • Windows Phone 获取 Isolated Storage 的空间信??/a>[代码]
    红薯
  • 获取 Windows Phone ??User-Agent 字符??/a>[代码]
    鉴客
  • Windows Phone 8 对等连接 —??蓝牙??WIFI 直连
  • ??WP 创建一个简单的动画程序
  • 免责声明 - 关于我们 - 联系我们 - 广告联系 - 友情链接 - 帮助中心 - 频道导航
    Copyright © 2015 www.zgxue.com All Rights Reserved