Breyta

Deila með


GeoCoordinateWatcher.TryStart(Boolean, TimeSpan) Method

Definition

Initiates the acquisition of data from the current location provider. This method returns synchronously.

public:
 virtual bool TryStart(bool suppressPermissionPrompt, TimeSpan timeout);
public bool TryStart (bool suppressPermissionPrompt, TimeSpan timeout);
abstract member TryStart : bool * TimeSpan -> bool
override this.TryStart : bool * TimeSpan -> bool
Public Function TryStart (suppressPermissionPrompt As Boolean, timeout As TimeSpan) As Boolean

Parameters

suppressPermissionPrompt
Boolean

true to suppress the permission dialog box; false to display the permission dialog box.

timeout
TimeSpan

Time in milliseconds to wait for the location provider to start before timing out.

Returns

true if data acquisition is started within the time period specified by timeout; otherwise, false.

Implements

Examples

The following example demonstrates how to call TryStart.

using System;
using System.Device.Location;

namespace GetLocationProperty
{
    class Program
    {
        static void Main(string[] args)
        {
            GetLocationProperty();
        }

        static void GetLocationProperty()
        {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();

            // Do not suppress prompt, and wait 1000 milliseconds to start.
            watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

            GeoCoordinate coord = watcher.Position.Location;

            if (coord.IsUnknown != true)
            {
                Console.WriteLine("Lat: {0}, Long: {1}",
                    coord.Latitude,
                    coord.Longitude);
            }
            else
            {
                Console.WriteLine("Unknown latitude and longitude.");
            }
        }
    }
}
Imports System.Device.Location

Module GetLocationProperty
    Public Sub GetLocationProperty()
        Dim watcher As New System.Device.Location.GeoCoordinateWatcher()
        watcher.TryStart(False, TimeSpan.FromMilliseconds(1000))

        Dim coord As GeoCoordinate = watcher.Position.Location

        If coord.IsUnknown <> True Then
            Console.WriteLine("Lat: {0}, Long: {1}", coord.Latitude, coord.Longitude)
        Else
            Console.WriteLine("Unknown latitude and longitude.")
        End If
    End Sub

    Public Sub Main()
        GetLocationProperty()
        Console.ReadLine()
    End Sub

End Module

Remarks

This method blocks execution of the calling thread during the time period specified by timeout. Use caution when calling TryStart from the user interface thread of your application.

Applies to