Windows phone 7 WP7 gps模拟器问题
我在使用微软提供的GPS模拟器时遇到了一个问题。 这是我的密码Windows phone 7 WP7 gps模拟器问题,windows-phone-7,gps,Windows Phone 7,Gps,我在使用微软提供的GPS模拟器时遇到了一个问题。 这是我的密码 public IGeoPositionWatcher<GeoCoordinate> Watcher { get; private set; } public IObservable<GeoCoordinate> ObservableGeoCoordinate { get; set; } private void InitializeGpsDevice() { try {
public IGeoPositionWatcher<GeoCoordinate> Watcher { get; private set; }
public IObservable<GeoCoordinate> ObservableGeoCoordinate { get; set; }
private void InitializeGpsDevice()
{
try
{
if (Watcher == null)
{
Watcher = new GpsEmulatorClient.GeoCoordinateWatcher();
}
ObservableGeoCoordinate = CreateObservableGeoPositionWatcher();
Watcher.Start();
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Failed to initialize GPS device:{0}", ex.Message), "GPS Error", MessageBoxButton.OK);
}
}
private IObservable<GeoCoordinate> CreateObservableGeoPositionWatcher()
{
var observable = Observable.FromEvent<GeoPositionChangedEventArgs<GeoCoordinate>>(
e => Watcher.PositionChanged += e,
e => Watcher.PositionChanged -= e
).Select(e => e.EventArgs.Position.Location);
return observable;
}
但OnPositionChanged事件从未引发。
任何人都可以提出原因?您是否首先在视图或页面构造函数中订阅了已加载事件
public MainPage()
{
InitializeComponent();
Loaded += OnLoaded;
}
如果GPassemulator运行且静止…GPS状态:NoData 试试这个 GPSEmulator/MainWindow.xaml.cs/line:391
string lat = currentPosition.X.ToString().Replace(",", ".");
string lon = currentPosition.Y.ToString().Replace(",", ".");
transmittedLocation = lat+","+lon;
好的,我想我明白了。尝试在CreateObservableGopositionWatcher中启动Watcher(就在返回observable之前)。可观测对象似乎与订阅前的Gps启动相关。不可能。即使有您的建议,也不会调用处理程序OnPositionChanged。我到底做错了什么?它不起作用:(我还尝试不使用反应扩展,并在onload方法中以标准方式注册观察者对象的PositionChanged事件处理程序,但似乎没有任何变化。观察者没有引发任何事件……实际上观察者状态id始终为NoData。但我不明白您建议在哪里编写此代码…可能在GPSEmulator的源代码中?你认为这是仿真器的问题吗?你明白了!这是GPS仿真器的错误!可能是区域设置或类似的问题。总之,你救了我!
string lat = currentPosition.X.ToString().Replace(",", ".");
string lon = currentPosition.Y.ToString().Replace(",", ".");
transmittedLocation = lat+","+lon;