简体   繁体   English

Windows Phone进度栏,同时搜索位置

[英]windows phone progress bar while searching location

I try activate a progressbar, while the app is searching for the location (after pressing a button) how can i solve it the best way? 我尝试激活进度条,而应用程序正在搜索位置(按按钮后),如何才能最好地解决呢?

the best would somehow to get an if else in there, wheater i got (the rigth) data from the geolocator and check that. 最好以某种方式获得一个另外的答案,惠特尔我从地理位置定位器获得了(严格性)数据并进行了检查。

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

Assuming you are using the ProgressIndicator in the SystemTry , Add the following to the OnNavigatedTo Method 假设您在SystemTry中使用ProgressIndicator ,则将以下内容添加到OnNavigatedTo方法中

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    SystemTray.ProgressIndicator = new ProgressIndicator();
}

Then create this method to set the ProgressIndicator . 然后创建此方法来设置ProgressIndicator

private void DisplayProgressIndicator(bool isvisible, string message = "")
{
    SystemTray.ProgressIndicator.Text = message;
    SystemTray.ProgressIndicator.IsIndeterminate = isvisible;
    SystemTray.ProgressIndicator.IsVisible = isvisible;
}

Then use the method created in the Eclips_Tap method. 然后使用在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;
        }                
    }
}

Hope this helps.. 希望这可以帮助..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM