-api-id | -api-type |
---|---|
T:Windows.Devices.Geolocation.Geolocator |
winrt class |
Provides access to the current geographic location.
Windows version | SDK version | Value added |
---|---|---|
1607 | 14393 | AllowFallbackToConsentlessPositions |
1607 | 14393 | DefaultGeoposition |
1607 | 14393 | IsDefaultGeopositionRecommended |
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;
}
Get current location, geolocation sample, Geotag sample (Windows 10)
location ID_CAP_LOCATION [Windows Phone]