Geolocator.GetGeopositionAsync Method

Definition

Overloads

GetGeopositionAsync()

Starts an asynchronous operation to retrieve the current location of the device.

GetGeopositionAsync(TimeSpan, TimeSpan)

Starts an asynchronous operation to retrieve the current location of the device.

GetGeopositionAsync()

Starts an asynchronous operation to retrieve the current location of the device.

public:
 virtual IAsyncOperation<Geoposition ^> ^ GetGeopositionAsync() = GetGeopositionAsync;
/// [Windows.Foundation.Metadata.Overload("GetGeopositionAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<Geoposition> GetGeopositionAsync();
[Windows.Foundation.Metadata.Overload("GetGeopositionAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<Geoposition> GetGeopositionAsync();
function getGeopositionAsync()
Public Function GetGeopositionAsync () As IAsyncOperation(Of Geoposition)

Returns

An asynchronous operation that, upon completion, returns a Geoposition marking the found location.

Attributes

Windows requirements

App capabilities
location ID_CAP_LOCATION [Windows Phone]

Remarks

This method throws an exception if the app doesn't have location permissions or if it times out with no location data retrieved. Therefore, the method should be called within a try/catch statement so that these common exception cases can be handled.

This method times out after 60 seconds, except when in Connected Standby. During Connected Standby, Geolocator objects can be instantiated but the Geolocator object will not find any sensors to aggregate and calls to GetGeopositionAsync will time out after 7 seconds. Upon time out, the StatusChanged event listeners will be called once with the NoData status, and the PositionChanged event listeners will never be called.

The user sets the privacy of their location data with the location privacy settings in the Settings app. Your app can access the user's location only when:

  • Location for this device... is turned on (not applicable to Windows 10 Mobile)
  • The location services setting, Location, is turned on
  • Under Choose apps that can use your location, your app is set to on

Important

Starting in Windows 10, call the RequestAccessAsync method before accessing the user’s location. At that time, your app must be in the foreground and RequestAccessAsync must be called from the UI thread. Your app can then handle the no-permissions case without throwing an exception.

See also

Applies to

GetGeopositionAsync(TimeSpan, TimeSpan)

Starts an asynchronous operation to retrieve the current location of the device.

public:
 virtual IAsyncOperation<Geoposition ^> ^ GetGeopositionAsync(TimeSpan maximumAge, TimeSpan timeout) = GetGeopositionAsync;
/// [Windows.Foundation.Metadata.Overload("GetGeopositionAsyncWithAgeAndTimeout")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<Geoposition> GetGeopositionAsync(TimeSpan const& maximumAge, TimeSpan const& timeout);
[Windows.Foundation.Metadata.Overload("GetGeopositionAsyncWithAgeAndTimeout")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<Geoposition> GetGeopositionAsync(System.TimeSpan maximumAge, System.TimeSpan timeout);
function getGeopositionAsync(maximumAge, timeout)
Public Function GetGeopositionAsync (maximumAge As TimeSpan, timeout As TimeSpan) As IAsyncOperation(Of Geoposition)

Parameters

maximumAge
TimeSpan TimeSpan

The maximum acceptable age of cached location data. A TimeSpan is a time period expressed in 100-nanosecond units.

timeout
TimeSpan TimeSpan

The timeout. A TimeSpan is a time period expressed in 100-nanosecond units.

Returns

An asynchronous operation that, upon completion, returns a Geoposition marking the found location.

Attributes

Windows requirements

App capabilities
location ID_CAP_LOCATION [Windows Phone]

Remarks

A location will be returned immediately if the latest location is within an acceptable age. Otherwise, a location will not be returned until the next change. In some cases, your app may receive location data that is older than the specified maximumAge value. This is because an additional age value will be calculated based on the desired accuracy setting, and your app will use whichever of the two ages is larger. For example, say a default accuracy of 500 meters corresponds to a maximum age of 30 seconds. In that case, your app could receive 20 second old data even if you set maximumAge to 10 seconds.

See also

Applies to