Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows phone应用程序中的位置跟踪问题_C#_Windows Phone 7 - Fatal编程技术网

C# windows phone应用程序中的位置跟踪问题

C# windows phone应用程序中的位置跟踪问题,c#,windows-phone-7,C#,Windows Phone 7,我的应用程序的一些用户抱怨跟踪端不起作用。我在屏幕顶部有一个GPS图标,当应用程序启动GeoCoordinateWatcher并试图获取当前位置时,图标会闪烁。完成此操作且正常后,图标停止闪烁,并显示消息“就绪”。用户报告发生了这种情况,但屏幕上的项目(如速度)从未更新。当应用程序保存它跟踪的位置时,什么都没有 这是跟踪部分的代码。在页面加载事件中,它调用以下命令 /// <summary> /// Starts tracking the user /// &

我的应用程序的一些用户抱怨跟踪端不起作用。我在屏幕顶部有一个GPS图标,当应用程序启动GeoCoordinateWatcher并试图获取当前位置时,图标会闪烁。完成此操作且正常后,图标停止闪烁,并显示消息“就绪”。用户报告发生了这种情况,但屏幕上的项目(如速度)从未更新。当应用程序保存它跟踪的位置时,什么都没有

这是跟踪部分的代码。在页面加载事件中,它调用以下命令

    /// <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();
         }));
    }
//
///开始跟踪用户
/// 
私有void StartTracking()
{
var app=(Application.Current作为app);
//检查用户是否启用了跟踪
如果(应用程序位置跟踪已启用)
{               
(新线程(()=>
{
//创建GeoWatcher
var watcher=新的地理坐标记录器(GeoPositionAccuracy.High){MovementThreshold=1};
//查看我们是否有使用手机定位服务的权限
if(watcher.Permission==geoppositionpermission.grated)
{
watcher.StatusChanged+=新事件处理程序(watcher\u StatusChanged);
var状态=可观察到的FromEvent(观察者,“状态改变”);
var readys=status.Where(o=>o.EventArgs.status==GeoPositionStatus.Ready);
var notReadys=status.Where(o=>o.EventArgs.status!=GeoPositionStatus.Ready);
var readyPos=从r到readys
从i到可观测间隔(时间跨度从秒(位置跟踪间隔))
.TakeUntil(notReadys)
其中(DateTime.Now-watcher.Position.Timestamp.DateTime)
{
如果(!已暂停)
{
this.Dispatcher.BeginInvoke(新操作(()=>
{
//获取当前速度(米/秒);
如果(!double.IsNaN(位置速度))
app.CurrentPos.CurrentSpeed=数学圆(loc.Location.Speed,2);
其他的
app.CurrentPos.CurrentSpeed=0;
//计算距离
如果(RunLocations.Count>0)
app.CurrentPos.DistanceMeters+=数学圆(新地理坐标(运行位置[RunLocations.Count-1])。纬度,
GPSLocations[GPSLocations.Count-1]。经度)。GetDistanceTo(loc.Location),2);
//添加位置
添加(新的GPSLocation()
{
纬度=位置纬度,
经度=位置经度,
高度=位置高度,
速度=app.CurrentRun.CurrentSpeed
});
//获得平均速度
app.CurrentPos.AverageSpeed=数学四舍五入((从r开始,单位为gps)
选择r.速度)。平均值(),2);
//设置最后一个位置供以后使用
Lastlocation=位置;
}));
}
});
//试着启动观察者
if(!watcher.TryStart(false,TimeSpan.FromSeconds(5)))
{
this.Dispatcher.BeginInvoke(新操作(()=>
{
Show(“试图获取您的位置时出错。无法进行跟踪。”);
}));
}
}
其他的
{
sbGpsFlash.Stop();//停止闪烁的gps符号
gpsStatus.Text=“拒绝”;
}
})).Start();
}
其他的
{
sbGpsFlash.Stop();//停止闪烁的gps符号
gpsStatus.Text=“已禁用”;
}
}
void watcher_status已更改(对象发送器、地理位置StatusChangedEventArgs e)
{
this.Dispatcher.BeginInvoke(新操作(()=>
{
gpsStatus.Text=e.Status.ToString();
开关(如状态)
{
案例地理位置状态。正在初始化:
gpsStatus.Text=“定位…”;
打破
案例地理位置状态。已禁用:
gpsStatus.Text=“已禁用”;
打破
案例地理位置status.NoData:
gpsStatus.Text=“无数据”;
打破
案例地理位置状态。准备就绪:
gpsStatus.Text=“就绪”;
打破
}
sbGpsFlash.Stop();
}));
}

有人能看到可能导致问题的代码问题吗?

创建您的地理坐标A