模拟Location数据:
Thread t = new Thread(StartLocationEmulation);
t.Start();
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.MovementThreshold = 35;
var gcwo = Observable.FromEvent>(
eh =>watcher.PositionChanged +=eh,
eh =>watcher.PositionChanged -=eh);
watcher.Start();
private void StartLocationEmulation()
{
var position = EmulatePositionChangedEvents().ToObservable();
position.Subscribe(ev => wait_PositionChanged(null, ev));
}
static IEnumerable> EmulatePositionChangedEvents()
{
Random random = new Random();
while (true)
{
double latitude = (random.NextDouble() * 180.0) – 90.0; // latitude is between -90 and 90
double longitude = (random.NextDouble() * 360.0) – 180.0; // longitude is between -180 and 180
yield return new GeoPositionChangedEventArgs
new GeoPosition
Thread.Sleep(random.Next(2000));
}
}
private void wait_PositionChanged(object sender, GeoPositionChangedEventArgs
{
Deployment.Current.Dispatcher.BeginInvoke(()=>MyPositionChanged(e));
}
private void MyPositionChanged(GeoPositionChangedEventArgs
{
this.textBlock1.Text = “Time: ” + e.Position.Timestamp. ToString(“yyyy-MM-dd hh:mm:ss”);
this.textBlock2.Text = “Latitude: ” + e.Position.Location.Latitude.ToString(“0.00″);
this.textBlock3.Text = “Longitude: ” + e.Position.Location.Longitude.ToString(“0.00″);
}
