WP7位置工具不会触发positionChanged事件

时间:2012-04-02 12:28:43

标签: windows-phone-7 gps location

尝试在this教程后测试使用位置的WP7应用。

我打开了其他工具,从VS启动模拟器,让app启动,然后在附加工具位置实用程序中将引脚置于实时模式,但不会触发任何事件。 我的代码有什么问题吗?

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;
    }

2 个答案:

答案 0 :(得分:3)

问题是你必须启动GeoCoordinateWatcher:

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

答案 1 :(得分:1)

您是否需要在GeoCoordinateWatcher实例上调用Start方法?

http://msdn.microsoft.com/en-us/library/ee808853.aspx