Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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 8 - Fatal编程技术网

C# 搜索位置时的windows phone进度条

C# 搜索位置时的windows phone进度条,c#,windows-phone-8,C#,Windows Phone 8,我尝试在应用程序搜索位置时激活进度条(按下按钮后) 我怎样才能以最好的方式解决它 最好的办法是在我从地理定位仪获取(右侧)数据并进行检查时,在那里获取一个if-else private async void Ellipse_Tap (object sender, System.Windows.Input.GestureEventArgs e) { Geolocator geolocator = new Geolocator(); //Set his accuracy in Met

我尝试在应用程序搜索位置时激活进度条(按下按钮后) 我怎样才能以最好的方式解决它

最好的办法是在我从地理定位仪获取(右侧)数据并进行检查时,在那里获取一个if-else

private async void Ellipse_Tap (object sender, System.Windows.Input.GestureEventArgs e)
{
    Geolocator geolocator = new Geolocator();
    //Set his accuracy in Meters 
    geolocator.DesiredAccuracyInMeters = 50;
    try
    {
        //The await guarantee the calls  to be returned on the thread from which they were called
        //Since it is call directly from the UI thread, the code is able to access and modify the UI directly when the call returns.
        Geoposition geoposition = await geolocator.GetGeopositionAsync(
            maximumAge: TimeSpan.FromMinutes(5),
            timeout: TimeSpan.FromSeconds(10)
            );

        //Relativer Nullpunkt

        delta_y = geoposition.Coordinate.Latitude - y;
        delta_x = geoposition.Coordinate.Longitude - x;

        Path.Visibility = Visibility.Visible;

    }
    //If an error is catch 2 are the main causes: the first is that you forgot to includ ID_CAP_LOCATION in your app manifest. 
    //The second is that the user doesn't turned on the Location Services
    catch (Exception ex)
    {
        if ((uint)ex.HResult == 0x80004004)
        {
            MessageBox.Show("Location is disabled in phone settings.");
            return;
            //Application.Current.Terminate();
        }
        //else
        {
            // something else happened during the acquisition of the location
        }
    }
}

假设您正在
SystemTry
中使用
ProgressIndicator
,请将以下内容添加到
OnNavigatedTo
方法中

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    SystemTray.ProgressIndicator = new ProgressIndicator();
}
然后创建此方法以设置
ProgressIndicator

private void DisplayProgressIndicator(bool isvisible, string message = "")
{
    SystemTray.ProgressIndicator.Text = message;
    SystemTray.ProgressIndicator.IsIndeterminate = isvisible;
    SystemTray.ProgressIndicator.IsVisible = isvisible;
}
然后使用Eclips_Tap方法中创建的方法

private async void Ellipse_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    Geolocator geolocator = new Geolocator();
    geolocator.DesiredAccuracyInMeters = 50;
    try
    {
        DisplayProgressIndicator(true, "Finding current location..."); // < SET THE PROGRESS INDICATOR

        Geoposition geoposition = await geolocator.GetGeopositionAsync(
            maximumAge: TimeSpan.FromMinutes(5),
            timeout: TimeSpan.FromSeconds(10)
            );

        delta_y = geoposition.Coordinate.Latitude - y;
        delta_x = geoposition.Coordinate.Longitude - x;

        Path.Visibility = Visibility.Visible;

        DisplayProgressIndicator(false); // << UNSET PROGRESS INDICATOR

    }
    catch (Exception ex)
    {
        if ((uint)ex.HResult == 0x80004004)
        {
            MessageBox.Show("Location is disabled in phone settings.");
            return;
        }                
    }
}
private async void椭圆\u点击(对象发送方,System.Windows.Input.GestureEventArgs e)
{
Geolocator Geolocator=新的Geolocator();
geolocator.DesiredAccuracyInMeters=50;
尝试
{
DisplayProgressIndicator(true,“查找当前位置…”);//<设置进度指示器
Geoposition Geoposition=等待geolocator.GetGeoPositionSync(
最大值:时间跨度从分钟(5),
超时:TimeSpan.FromSeconds(10)
);
delta_y=地理位置坐标纬度-y;
delta_x=地理位置.坐标.经度-x;
Path.Visibility=可见性.Visibility;
显示进度指示器(假)//