【问题标题】:GeoCoordinateWatcher isn't working after migration to WP8迁移到 WP8 后 GeoCoordinateWatcher 无法正常工作
【发布时间】:2014-02-09 04:46:57
【问题描述】:

我为 windows phone 7.1 开发了一个导航应用程序。那里运行良好。更新到 8.0 后,我的 GeoCoordinateWatcher 不再工作。我知道我可以改用 Geolocator,但我拒绝这样做,因为时间不够。

对于我的应用程序,我读取了观察者的当前位置,以将其存储为具有位置信息的对象实例。当我保存对象实例时,经度和纬度为 0.0。即使我在模拟器中更改位置仍然是 0.0。同样的问题出现在我使用 GeoCoordinateWatcher 的其他页面上。它不起作用。正如我已经说过的,在 WP 7.1 - 7.8 上它运行良好。

    public Map()
    {
        InitializeComponent();

        watcher = new GeoCoordinateWatcher();
        watcher.MovementThreshold = 20;
        watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
        watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
    }

    void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
    {
        if (e.Position.Location.IsUnknown)
        {
            MessageBox.Show("Please wait while your prosition is determined.");
            return;
        }

        geo.Latitude = e.Position.Location.Latitude;
        geo.Longitude = e.Position.Location.Longitude;
    }

【问题讨论】:

    标签: windows-phone-7 geolocation windows-phone-8


    【解决方案1】:

    试试这个代码:

        GeoCoordinateWatcher watch;
    public GeoCoordinate loc = null;
    public MainPage()
    {
        InitializeComponent();
        if (watch == null)
        {
            watch = new GeoCoordinateWatcher(GeoPositionAccuracy.High)
            {
                MovementThreshold=10
            };
            watch.Start();
            watch.PositionChanged += watch_PositionChanged;
        }
    }
    void watch_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
    {
        //throw new NotImplementedException();
        Dispatcher.BeginInvoke(()=>LocUpdate(e));
    }
    
    void LocUpdate(GeoPositionChangedEventArgs<GeoCoordinate> e)
    {
        try
        {
            location = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
    
    
        }
        catch
        {
            MessageBox.Show("Error");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-18
      • 2013-07-07
      • 2019-04-24
      相关资源
      最近更新 更多