0

私のアプリの一部のユーザーは、追跡側が機能しないと不満を漏らしています。アプリがGeoCoordinateWatcherを起動し、現在の場所を取得しようとしている間、画面の上部にGPSアイコンが点滅します。これが完了して問題がなければ、アイコンの点滅が止まり、準備完了というメッセージが表示されます。ユーザーはこれが発生すると報告していますが、速度などの画面上の項目は更新されません. アプリが追跡した場所を保存すると、そこには何もありません。

追跡部分のコードは次のとおりです。ページ読み込みイベントでは、次を呼び出します

    /// <summary>
    /// Starts tracking the user
    /// </summary>
    private void StartTracking()
    {
        var app = (Application.Current as App);

        // check to see if tracking is enabled by the user                    
        if (app.LocationTrackingIsEnabled)
        {               
                (new Thread(() =>
                {
                    // Create the GeoWatcher
                    var watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High) { MovementThreshold = 1 };

                    // Check to see if we have permission to use the location services of the phone
                    if (watcher.Permission == GeoPositionPermission.Granted)
                    {
                        watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);

                        var status = Observable.FromEvent<GeoPositionStatusChangedEventArgs>(watcher, "StatusChanged");
                        var readys = status.Where(o => o.EventArgs.Status == GeoPositionStatus.Ready);
                        var notReadys = status.Where(o => o.EventArgs.Status != GeoPositionStatus.Ready);
                        var readyPos = from r in readys
                                       from i in Observable.Interval(TimeSpan.FromSeconds(LocationTrackInterval))
                                       .TakeUntil(notReadys)
                                       where (DateTime.Now - watcher.Position.Timestamp.DateTime) < TimeSpan.FromSeconds(12)
                                       select watcher.Position;

                        LocationSubscribe = readyPos.Subscribe(loc =>
                        {
                            if (!HasPaused)
                            {
                                this.Dispatcher.BeginInvoke(new Action(() =>
                                {
                                    // Get current speed (meters per second);
                                    if (!double.IsNaN(loc.Location.Speed))
                                        app.CurrentPos.CurrentSpeed = Math.Round(loc.Location.Speed, 2);
                                    else
                                        app.CurrentPos.CurrentSpeed = 0;

                                    // Calculate distance
                                    if (RunLocations.Count > 0)
                                        app.CurrentPos.DistanceMeters += Math.Round(new GeoCoordinate(RunLocations[RunLocations.Count - 1].Latitude,
                                            GPSLocations[GPSLocations.Count - 1].Longitude).GetDistanceTo(loc.Location), 2);

                                    // Add Location
                                    GPSLocations.Add(new GPSLocation()
                                    {
                                        Latitude = loc.Location.Latitude,
                                        Longitude = loc.Location.Longitude,
                                        Altitude = loc.Location.Altitude,
                                        Speed = app.CurrentRun.CurrentSpeed
                                    });

                                    // Get the average speed
                                    app.CurrentPos.AverageSpeed = Math.Round((from r in GPSLocations
                                                                              select r.Speed).Average(), 2);


                                    // Set last position for use later
                                    Lastlocation = loc.Location;
                                }));
                            }
                        });

                        // Try and start the watcher
                        if (!watcher.TryStart(false, TimeSpan.FromSeconds(5)))
                        {
                            this.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                MessageBox.Show("There was an error trying to get your location. Tracking is not possible.");
                            }));
                        }
                    }
                    else
                    {
                        sbGpsFlash.Stop(); // stop the flashing gps symbol
                        gpsStatus.Text = "Denied";
                    }

                })).Start();                
        }
        else
        {
            sbGpsFlash.Stop(); // stop the flashing gps symbol
            gpsStatus.Text = "Disabled";
        }
    }

void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
    {
         this.Dispatcher.BeginInvoke(new Action(() =>
         {
             gpsStatus.Text = e.Status.ToString();

             switch (e.Status)
             {
                 case GeoPositionStatus.Initializing:
                     gpsStatus.Text = "Locating...";
                     break;
                 case GeoPositionStatus.Disabled:
                     gpsStatus.Text = "Disabled";
                     break;
                 case GeoPositionStatus.NoData:
                     gpsStatus.Text = "No Data";
                     break;
                 case GeoPositionStatus.Ready:
                     gpsStatus.Text = "Ready";
                     break;                                     
             }

             sbGpsFlash.Stop();
         }));
    }

問題を引き起こす可能性のあるコードの問題を誰でも見ることができますか?

4

2 に答える 2

0

メインスレッドでgeocoordinatewatcherを作成します

于 2013-01-18T09:08:53.127 に答える