Long Running Location Application (Windows Embedded CE 6.0)
1/6/2010
The following shows a typical application usage of the Location Framework for an application that requires continuous position updates for lat/long. Note error checking has been excluded to increase clarity, though any Location Framework API may fail.
Syntax
// Base handle to Location Framework.
// This will not cause any plugins to be started
HLOCATION hLoc = LocationOpen(LOCATION_FRAMEWORK_VERSION_1,NULL,0);
// Event that Location Framework signals when a new position is
// generated by a plugin of this particular type
HANDLE hNewReportEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
// Event that Location Framework signals when the underlying
// state of a plugin that generates this report changes
HANDLE hPluginStateChangeEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
// Indicate to Location Framework that lat/long should be generated,
// if not already. This will cause location plugin(s) to be started
LocationRegisterForReport(hLoc, hNewReportEvent, hPluginStateChangeEvent,
LOCATION_LATLONG_GUID,0);
while (appWishesToGetLocation) {
// Wait for new report to be signaled
WaitForSingleObject(hNewReportEvent,maxTimeout);
if (eventTimedOut) { PossiblyIndicateErrorToUser(); continue; }
// Retrieve the report
LOCATION_REPORT_LATLONG currentPosition;
DWORD currentPositionSize = sizeof(currentPosition);
LocationGetReport(hLoc, LOCATION_LATLONG_GUID,10000,
¤tPosition,¤tPositionSize,0);
PerformActionBasedOnReport(¤tPosition);
}
// No longer need this report type
LocationUnRegisterForReport(hLoc,LOCATION_LATLONG_GUID,0);
// Close down our open handle of location framework
LocationClose(hLoc);