Geolocator Geolocator Geolocator Geolocator Geolocator Class

Definition

Provides access to the current geographic location.

public : sealed class Geolocator : IGeolocator, IGeolocator2, IGeolocatorWithScalarAccuracy
struct winrt::Windows::Devices::Geolocation::Geolocator : IGeolocator, IGeolocator2, IGeolocatorWithScalarAccuracy
public sealed class Geolocator : IGeolocator, IGeolocator2, IGeolocatorWithScalarAccuracy
Public NotInheritable Class Geolocator Implements IGeolocator, IGeolocator2, IGeolocatorWithScalarAccuracy
var geolocator = new geolocator();
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
location ID_CAP_LOCATION [Windows Phone]

Examples

This example shows how to use the Geolocator class to retrieve the device's location. For more info, see Get current location.

using Windows.Devices.Geolocation;
...
var accessStatus = await Geolocator.RequestAccessAsync();
switch (accessStatus)
{
    case GeolocationAccessStatus.Allowed:
        // notify user: Waiting for update

        // If DesiredAccuracy or DesiredAccuracyInMeters are not set (or value is 0), DesiredAccuracy.Default is used.
        Geolocator geolocator = new Geolocator { DesiredAccuracyInMeters = _desireAccuracyInMetersValue };

        // Subscribe to StatusChanged event to get updates of location status changes
        _geolocator.StatusChanged += OnStatusChanged;

        // Carry out the operation
        Geoposition pos = await geolocator.GetGeopositionAsync();

        UpdateLocationData(pos);
        // notify user: Location updated
        break;

    case GeolocationAccessStatus.Denied:
        // notify user: Access to location is denied

        break;

    case GeolocationAccessStatus.Unspecified:
        // notify user: Unspecified error
        break;
}

Constructors

Geolocator() Geolocator() Geolocator() Geolocator() Geolocator()

Initializes a new Geolocator object.

Properties

DefaultGeoposition DefaultGeoposition DefaultGeoposition DefaultGeoposition DefaultGeoposition

Gets the location manually entered into the system by the user, to be utilized if no better options exist.

DesiredAccuracy DesiredAccuracy DesiredAccuracy DesiredAccuracy DesiredAccuracy

The accuracy level at which the Geolocator provides location updates.

DesiredAccuracyInMeters DesiredAccuracyInMeters DesiredAccuracyInMeters DesiredAccuracyInMeters DesiredAccuracyInMeters

Gets or sets the desired accuracy in meters for data returned from the location service.

IsDefaultGeopositionRecommended IsDefaultGeopositionRecommended IsDefaultGeopositionRecommended IsDefaultGeopositionRecommended IsDefaultGeopositionRecommended

Indicates whether the user should be prompted to set a default location manually.

LocationStatus LocationStatus LocationStatus LocationStatus LocationStatus

The status that indicates the ability of the Geolocator to provide location updates.

MovementThreshold MovementThreshold MovementThreshold MovementThreshold MovementThreshold

The distance of movement, in meters, relative to the coordinate from the last PositionChanged event, that is required for the Geolocator to raise a PositionChanged event.

ReportInterval ReportInterval ReportInterval ReportInterval ReportInterval

The requested minimum time interval between location updates, in milliseconds. If your application requires updates infrequently, set this value so that location services can conserve power by calculating location only when needed.

Methods

AllowFallbackToConsentlessPositions() AllowFallbackToConsentlessPositions() AllowFallbackToConsentlessPositions() AllowFallbackToConsentlessPositions() AllowFallbackToConsentlessPositions()

Sets the Geolocator to use coarse location as a fallback option (see Remarks).

GetGeopositionAsync() GetGeopositionAsync() GetGeopositionAsync() GetGeopositionAsync() GetGeopositionAsync()

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

GetGeopositionAsync(TimeSpan, TimeSpan) GetGeopositionAsync(TimeSpan, TimeSpan) GetGeopositionAsync(TimeSpan, TimeSpan) GetGeopositionAsync(TimeSpan, TimeSpan) GetGeopositionAsync(TimeSpan, TimeSpan)

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

GetGeopositionHistoryAsync(DateTime) GetGeopositionHistoryAsync(DateTime) GetGeopositionHistoryAsync(DateTime) GetGeopositionHistoryAsync(DateTime) GetGeopositionHistoryAsync(DateTime)

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

Note

This API is not available to all Windows apps. Unless your developer account is specially provisioned by Microsoft, calls to these APIs will fail at runtime.

GetGeopositionHistoryAsync(DateTime, TimeSpan) GetGeopositionHistoryAsync(DateTime, TimeSpan) GetGeopositionHistoryAsync(DateTime, TimeSpan) GetGeopositionHistoryAsync(DateTime, TimeSpan) GetGeopositionHistoryAsync(DateTime, TimeSpan)

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

Note

This API is not available to all Windows apps. Unless your developer account is specially provisioned by Microsoft, calls to these APIs will fail at runtime.

RequestAccessAsync() RequestAccessAsync() RequestAccessAsync() RequestAccessAsync() RequestAccessAsync()

Requests permission to access location data.

Events

PositionChanged PositionChanged PositionChanged PositionChanged PositionChanged

Raised when the location is updated.

StatusChanged StatusChanged StatusChanged StatusChanged StatusChanged

Raised when the ability of the Geolocator to provide updated location changes.

See Also