ILocationEvents::OnLocationChanged-Methode (locationapi.h)
[Die Win32-Standort-API ist für die Verwendung in den im Abschnitt Anforderungen angegebenen Betriebssystemen verfügbar. Es kann in nachfolgenden Versionen geändert oder entfernt werden. Verwenden Sie stattdessen die Windows.Devices.Geolocation-API . ]
Wird aufgerufen, wenn ein neuer Standortbericht verfügbar ist.
Syntax
HRESULT OnLocationChanged(
[in] REFIID reportType,
[in] ILocationReport *pLocationReport
);
Parameter
[in] reportType
REFIID , die die Schnittstellen-ID des Berichtstyps enthält, der in pLocationReport enthalten ist.
[in] pLocationReport
Zeiger auf die ILocationReport-instance, die den neuen Speicherortbericht enthält.
Rückgabewert
Wenn diese Methode erfolgreich ist, wird S_OK zurückgegeben. Andernfalls wird ein Fehlercode HRESULT zurückgegeben.
Hinweise
ILocationReport ist die Basisschnittstelle bestimmter Standortberichtstypen. Die tatsächliche Schnittstelle, die der Aufrufer für pLocationReport empfängt, stimmt mit dem durch reportType angegebenen Typ überein.
Wenn die Anwendung OnLocationChanged als Ergebnis ihrer ersten Verwendung von location aufruft, kann der Aufruf dazu führen, dass eine Benachrichtigung in der Taskleiste angezeigt wird und ein Location Activity-Ereignis Ereignisanzeige protokolliert wird.
Beispiele
Die folgende Beispielimplementierung von OnLocationChanged behandelt das Positionsänderungsereignis für einen Breiten-/Längengradbericht. Diese Implementierung gibt die folgenden Informationen zu einem Breiten-/Längengrad-Positionsänderungsereignis aus: den Zeitstempel, die Sensor-ID, den Breitengrad, den Längengrad, den Fehlerradius, die Höhe und den Höhenfehler.
// This is called when there is a new location report
STDMETHODIMP CLocationEvents::OnLocationChanged(REFIID reportType, ILocationReport* pLocationReport)
{
// If the report type is a Latitude/Longitude report (as opposed to IID_ICivicAddressReport or another type)
if (IID_ILatLongReport == reportType)
{
CComPtr<ILatLongReport> spLatLongReport;
// Get the ILatLongReport interface from ILocationReport
if ((SUCCEEDED(pLocationReport->QueryInterface(IID_PPV_ARGS(&spLatLongReport)))) && (NULL != spLatLongReport.p))
{
// Print the Report Type GUID
wchar_t szGUID[64];
wprintf(L"\nReportType: %s", GUIDToString(IID_ILatLongReport, szGUID, ARRAYSIZE(szGUID)));
// Print the Timestamp and the time since the last report
SYSTEMTIME systemTime;
if (SUCCEEDED(spLatLongReport->GetTimestamp(&systemTime)))
{
// Compute the number of 100ns units that difference between the current report's time and the previous report's time.
ULONGLONG currentTime = 0, diffTime = 0;
if (TRUE == SystemTimeToFileTime(&systemTime, (FILETIME*)¤tTime))
{
diffTime = (currentTime > m_previousTime) ? (currentTime - m_previousTime) : 0;
}
wprintf(L"\nTimestamp: YY:%d, MM:%d, DD:%d, HH:%d, MM:%d, SS:%d, MS:%d [%I64d]\n",
systemTime.wYear,
systemTime.wMonth,
systemTime.wDay,
systemTime.wHour,
systemTime.wMinute,
systemTime.wSecond,
systemTime.wMilliseconds,
diffTime / 10000); // Display in milliseconds
m_previousTime = currentTime; // Set the previous time to the current time for the next report.
}
// Print the Sensor ID GUID
GUID sensorID = {0};
if (SUCCEEDED(spLatLongReport->GetSensorID(&sensorID)))
{
wchar_t szGUID[64];
wprintf(L"SensorID: %s\n", GUIDToString(sensorID, szGUID, ARRAYSIZE(szGUID)));
}
DOUBLE latitude = 0, longitude = 0, altitude = 0, errorRadius = 0, altitudeError = 0;
// Print the Latitude
if (SUCCEEDED(spLatLongReport->GetLatitude(&latitude)))
{
wprintf(L"Latitude: %f\n", latitude);
}
// Print the Longitude
if (SUCCEEDED(spLatLongReport->GetLongitude(&longitude)))
{
wprintf(L"Longitude: %f\n", longitude);
}
// Print the Altitude
if (SUCCEEDED(spLatLongReport->GetAltitude(&altitude)))
{
wprintf(L"Altitude: %f\n", altitude);
}
else
{
// Altitude is optional and may not be available
wprintf(L"Altitude: Not available.\n");
}
// Print the Error Radius
if (SUCCEEDED(spLatLongReport->GetErrorRadius(&errorRadius)))
{
wprintf(L"Error Radius: %f\n", errorRadius);
}
// Print the Altitude Error
if (SUCCEEDED(spLatLongReport->GetAltitudeError(&altitudeError)))
{
wprintf(L"Altitude Error: %f\n", altitudeError);
}
else
{
// Altitude Error is optional and may not be available
wprintf(L"Altitude Error: Not available.\n");
}
}
}
return S_OK;
}
Anforderungen
Anforderung | Wert |
---|---|
Unterstützte Mindestversion (Client) | Windows 7 [nur Desktop-Apps],Windows 7 |
Unterstützte Mindestversion (Server) | Nicht unterstützt |
Zielplattform | Windows |
Kopfzeile | locationapi.h |
DLL | LocationAPI.dll |