2012-04-02 42 views
0

试图测试我的WP7应用程序,该应用程序使用this教程后的位置。WP7位置工具不会触发positionChanged事件

我有其他工具打开,从VS启动模拟器,让应用程序启动,然后我在其他工具位置实用程序中的实时模式中放置一个PIN,但没有事件被触发。 我的代码有什么问题吗?

public MainPage() 
     { 
      InitializeComponent(); 
      InitWatcher(); 
     } 

private void InitWatcher() 
    { 
     geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); 
     geoWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(geoWatcher_PositionChanged); 
     geoWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(geoWatcher_StatusChanged); 
    } 

    private void geoWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) 
    { 
     var lol = e; 
    } 

    private void geoWatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e) 
    { 
     var FK = e; 
    } 

回答

3

的问题是,你必须开始GeoCoordinateWatcher:

geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); 
geoWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(geoWatcher_PositionChanged); 
geoWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(geoWatcher_StatusChanged); 
geoWatcher.Start(); 
+0

打我吧:-) – 2012-04-02 12:35:26

+0

感谢队友,这个工作。 – user473104 2012-04-02 12:43:44