Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 2.12 KB

geolocator.md

File metadata and controls

70 lines (49 loc) · 2.12 KB
-api-id -api-type
T:Windows.Devices.Geolocation.Geolocator
winrt class

Windows.Devices.Geolocation.Geolocator

-description

Provides access to the current geographic location.

-remarks

Version history

Windows version SDK version Value added
1607 14393 AllowFallbackToConsentlessPositions
1607 14393 DefaultGeoposition
1607 14393 IsDefaultGeopositionRecommended

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

-see-also

Get current location, geolocation sample, Geotag sample (Windows 10)

-capabilities

location ID_CAP_LOCATION [Windows Phone]