tag that you added in the previous task, add the following script section:
Each time the location report status changes, the event handler will forward the new status to the MicrosoftGadget object.
Task 4: Handle the New Report Event
This gadget handles location report events. When a new location report becomes available through the event mechanism, the gadget calls a function in the MicrosoftGadget object to retrieve the current latitude and longitude from the report. The script code that automatically updates the weather gadget's location has already been written for you. That code resembles the code you wrote in the previous exercise. To handle the new report event, add the following code after the closing curly bracket (}) of the StatusChanged function that you added in the previous task:
function factory::NewLatLongReport(report)
{
MicrosoftGadget.getWeatherUpdate();
}
Task 5: Package the Weather Gadget
You must package all the weather gadget files into a zip archive.
Open the Weather Gadget folder.
Press CTRL + A to select all files in the right pane.
Right-click one of the selected files, point to Send To, and then click Compressed (zipped) Folder. Windows creates a new compressed folder.
Press F2 to rename the compressed folder.
Rename the folder "Weather.gadget." Click Yes, when you are prompted.
You will see that Windows changes the icon for the compressed folder to a gadget icon.
Exercise 3: Run the Gadgets
Now that you have written the code, you can run the gadgets to see the results.
Task 1: Install and Run the Location Gadget
You can now install and run the Location gadget.
In the Location Gadget Explorer window, double-click LocationSample.gadget to install the gadget.
Click Install, when you are prompted.
Right-click anywhere on the Desktop.
Click Gadgets.
Double-click the Location Sample gadget.
The Location Sample gadget opens. You will notice that the gadget displays a map with a push pin that shows the current location as Los Angeles. This location was coded into the gadget as the default location.
Task 2: Install and Run the Weather Gadget
In the Weather Gadget Explorer window, double-click Weather.gadget to install the gadget.
Click Install, when you are prompted.
Right-click anywhere on the Desktop.
Click Gadgets.
Double-click the Weather gadget.
The Weather gadget opens. You will notice that the gadget displays the current weather conditions for Redmond, Washington. The red square indicates that the Location API has not provided location data.
Task 3: Enable the Location Provider
Typically, hardware devices, such as GPS devices, provide location data through a device driver. For this lab, we have installed a device driver that imitates a hardware device. The lab's device driver reads location coordinates from a short text script. The script provides latitude and longitude information, along with timing interval information. This technique enables you to see the effects of location changes as if you were moving across the United States.
Double-click the Location and Other Sensors shortcut on the Desktop.
For the Microsoft Sensor Skeleton Device Sample sensor, select the Enabled check box.
Click Apply.
Close the Control Panel.
The two gadgets you created will now receive events from the Location API. About once every second, you will see the location change on the map in the Location Sample gadget.
The Weather gadget will change its weather report based on the latest location data. The green square indicates that the Location API is actively providing data. A yellow square indicates that the Location API provided the latest data, but no weather report is available for the current location.
Lab Summary
In this lab you performed the following exercises.
Created a Desktop gadget that shows the current location.
Created a Desktop gadget that displays the weather conditions for the current location.
Learned how to enable a location sensor and run the gadgets.
In this hands-on lab you were introduced to using the Location API in Windows 7.