次の方法で共有


Opportunistic Determination of Location (Windows Embedded CE 6.0)

1/6/2010

Because the process of determining a device’s physical location may incur a large battery hit, some applications may wish to use location information only opportunistically. For instance, imagine a Today Screen plugin that shows the local weather report automatically. While nice to have, just updating a Today Screen view may not be a feature many users wish to take even a daily drain on their battery device to achieve.

To enable scenarios like this, the Location Framework does not require applications to explicitly register for reports. Instead, they can simply call LocationGetReport directly. LocationGetReport never calls directly into a plugin DLL, but instead attempts to read the last known position for a particular report type (which the Location Framework automatically caches). This could be for many reasons, such as a weather report or because it is not willing to expend the power.

Syntax

HLOCATION hLoc = LocationOpen(LOCATION_FRAMEWORK_VERSION_1,NULL,0);

LOCATION_REPORT_LATLONG currentPosition;
DWORD currentPositionSize = sizeof(currentPosition);

LocationGetReport(hLoc, LOCATION_LATLONG_GUID,10000,
   &currentPosition,&currentPositionSize,0);

if (succeeded) {
   ContactWeatherServerWithPosition(&currentPosition);
}
else {
   IndicateNoWeatherDataAvailable(); 
}

Remarks

In the above sample, we may imagine that the Today Screen would wish to first see if data was available already and if not, query for the current position once. In this case, it would use a hybrid approach of this and the Long Running Location Application topic sample. Initially it would call LocationGetReport to see if cached data were available, and if not it would call LocationRegisterForReport.

See Also

Other Resources

Location Framework Samples