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
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:
_rootPage.NotifyUser("Waiting for update...", NotifyType.StatusMessage);
// 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);
_rootPage.NotifyUser("Location updated.", NotifyType.StatusMessage);
break;
case GeolocationAccessStatus.Denied:
_rootPage.NotifyUser("Access to location is denied.", NotifyType.ErrorMessage);
LocationDisabledMessage.Visibility = Visibility.Visible;
UpdateLocationData(null);
break;
case GeolocationAccessStatus.Unspecified:
_rootPage.NotifyUser("Unspecified error.", NotifyType.ErrorMessage);
UpdateLocationData(null);
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
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. |