簡體   English   中英

Windows Phone進度欄,同時搜索位置

[英]windows phone progress bar while searching location

我嘗試激活進度條,而應用程序正在搜索位置(按按鈕后),如何才能最好地解決呢?

最好以某種方式獲得一個另外的答案,惠特爾我從地理位置定位器獲得了(嚴格性)數據並進行了檢查。

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

希望這可以幫助..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM