Geolocator Class

Bietet Zugriff auf den aktuellen geografischen Standort.

Syntax


var geolocator = new Windows.Devices.Geolocation.Geolocator();

Attribute

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Member

GeolocatorKlasse hat diese Membertypen:

Konstruktoren

GeolocatorKlasse hat diese Konstruktoren.

KonstruktorBeschreibung
Geolocator Initializes a new Geolocator object.

 

Ereignisse

GeolocatorKlasse hat diese Ereignisse.

EreignisBeschreibung
PositionChanged Raised when the location is updated.
StatusChanged Raised when the ability of the Geolocator to provide updated location changes.

 

Methoden

The Geolocator Klasse hat diese Methoden. Mit C#, Visual Basic und C++ erbt es auch Methoden aus Object Klasse.

MethodeBeschreibung
GetGeopositionAsync() Starts an asynchronous operation to retrieve the current location of the device.
GetGeopositionAsync(TimeSpan, TimeSpan) Starts an asynchronous operation to retrieve the current location of the device.

 

Eigenschaften

Der GeolocatorKlasse hat diese Eigenschaften.

EigenschaftZugriffstypBeschreibung

DesiredAccuracy

Lese-/SchreibzugriffThe accuracy level at which the Geolocator provides location updates.

DesiredAccuracyInMeters

Lese-/SchreibzugriffGets or sets the desired accuracy in meters for data returned from the location service.

LocationStatus

SchreibgeschütztThe status that indicates the ability of the Geolocator to provide location updates.

MovementThreshold

Lese-/SchreibzugriffGets and sets 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

Lese-/SchreibzugriffThe requested minimum time interval between location updates, in milliseconds. If your application requires updates infrequently, set this value so that the location provider can conserve power by calculating location only when needed.

 

Hinweise

Die erste Verwendung des Geolocator-Objekts zum Aufruf von GetGeopositionAsync oder zum Abonnieren von PositionChanged-Ereignissen muss im UI-Thread ausgeführt werden, damit dem Benutzer die Zustimmungsaufforderung angezeigt werden kann. Weitere Informationen finden Sie unter im Abschnitt zu Richtlinien für Geräte, mit denen auf persönliche Daten zugegriffen wird.

Beispiele

Dieses Beispiel veranschaulicht das Aufrufen von GetGeopositionAsync.


    var loc = null;

    function getloc() {
        if (loc == null) {
            loc = new Windows.Devices.Geolocation.Geolocator();
        }
        if (loc != null) {
            loc.getGeopositionAsync().then(getPositionHandler, errorHandler);
        }
    }

    function getPositionHandler(pos) {
        document.getElementById('latitude').innerHTML = pos.coordinate.latitude;
        document.getElementById('longitude').innerHTML = pos.coordinate.longitude;
        document.getElementById('accuracy').innerHTML = pos.coordinate.accuracy;
        document.getElementById('geolocatorStatus').innerHTML =
                getStatusString(loc.locationStatus);
    }

    function errorHandler(e) {
        document.getElementById('errormsg').innerHTML = e.message;
        // Display an appropriate error message based on the location status.
        document.getElementById('geolocatorStatus').innerHTML =
            getStatusString(loc.locationStatus);
    }

    function getStatusString(locStatus) {
        switch (locStatus) {
            case Windows.Devices.Geolocation.PositionStatus.ready:
                // Location data is available
                return "Location is available.";
                break;
            case Windows.Devices.Geolocation.PositionStatus.initializing:
                // This status indicates that a location device is still initializing
                return "Location devices are still initializing.";
                break;
            case Windows.Devices.Geolocation.PositionStatus.noData:
                // No location data is currently available 
                return "Data from location services is currently unavailable.";
                break;
            case Windows.Devices.Geolocation.PositionStatus.disabled:
                // The app doesn't have permission to access location,
                // either because location has been turned off.
                return "Your location is currently turned off. " +
                    "Change your settings through the Settings charm " +
                    " to turn it back on.";
                break;
            case Windows.Devices.Geolocation.PositionStatus.notInitialized:
                // This status indicates that the app has not yet requested
                // location data by calling GetGeolocationAsync() or 
                // registering an event handler for the positionChanged event. 
                return "Location status is not initialized because " +
                    "the app has not requested location data.";
                break;
            case Windows.Devices.Geolocation.PositionStatus.notAvailable:
                // Location is not available on this version of Windows
                return "You do not have the required location services " +
                    "present on your system.";
                break;
            default:
                break;
        }
    }


Anforderungen

Mindestens unterstützter Client

Windows 8 [Nur Windows Store-Apps]

Mindestens unterstützter Server

Keine unterstützt [Nur Windows Store-Apps]

Mindestens unterstütztes Telefon

Windows Phone 8

Namespace

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

Metadaten

Windows.winmd

Capabilities

location
ID_CAP_LOCATION [Windows Phone]

 

 

Anzeigen:
© 2014 Microsoft