Geolocator.GetGeopositionAsync(TimeSpan, TimeSpan) | getGeopositionAsync(TimeSpan, TimeSpan) method

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

Syntax


geolocator.getGeopositionAsync(maximumAge, timeout).done( /* Your success and error handlers */ );

Parameters

maximumAge

Type: Number [JavaScript] | System.TimeSpan [.NET] | Windows::Foundation::TimeSpan [C++]

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

timeout

Type: Number [JavaScript] | System.TimeSpan [.NET] | Windows::Foundation::TimeSpan [C++]

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

Return value

Type: IAsyncOperation<Geoposition>

Provides methods for starting the asynchronous request for location data and handling its completion.

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. That’s 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.

Important  Call the RequestAccessAsync 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. Until the user grants your app permission to their location, your app can't access location data.

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.

Tip  When using the emulator, don't forget to change the location to trigger the PositionChanged event.

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 or location history only when:

  • Location is turned on
  • The setting Let Windows and apps you choose use your location and location history is turned on
  • Under Choose apps that can use your location, your app is set to on

Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Devices.Geolocation
Windows::Devices::Geolocation [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Capabilities

ID_CAP_LOCATION [Windows Phone]

Requirements (operating system)

Minimum supported client

Windows 8

Minimum supported server

None supported

Minimum supported phone

Windows Phone 8

Namespace

Windows.Devices.Geolocation
Windows::Devices::Geolocation [C++]

Metadata

Windows.winmd

Capabilities

ID_CAP_LOCATION [Windows Phone]

See also

Detect a user's location
Respond to location updates
Set up a geofence
Geoposition
Geocoordinate
Geolocator
GetGeopositionAsync

 

 

Show:
© 2015 Microsoft