|Figure 4. The External Event Generator: The EEG window allows developers to send simulated location and orientation information to their MIDlets running in the WTK emulators.|
Location API Support
With many devices now containing Global Position System (GPS) receivers or other meanslike the use of triangulation from a radio network to obtain the location of the device,the WTK now includes support for the Location API. The Location API gives MIDlet applications access to a device's present geographic location and orientation, and access to databases of known landmarks stored on the device. The Location API is an optional J2ME package that can be used with many J2ME profiles. As indicated above, however, it must be used with CLDC 1.1.
What might be the neatest thing about WTK's support for the Location API is the built-in test facility to simulate the device providing location and orientation information to the application. Using the External Event Generator window (see Figure 4), developers can either set the location/orientation of the device directly or run a script mimicking the device on the move.
|Figure 5. Code Download Location: After downloading the example application, you can unzip the contents right into the WTK23/apps directory. As shown here, you should have a new WayPointCollector directory containing all the code and associated build files.|
To help demonstrate WTK's support of the Location API and the External Event Generator (EEG) window, I have created a small demonstration application that you can download and run. The zip file associated with this article should be extracted right into the apps directory of your WTK 2.3 directory. When extracting the code, a WayPointCollector folder will be created for you in your Wireless Toolkit directory. Your WTK23/apps directory should look something similar to what is found in Figure 5.
When I was in the military, before the era of GPS and Loran systems, the only way to obtain your location and elevation was via Army provided maps. Setting aside the human error factor, if the map you were using was poor, then the location and elevation information you were reporting was also usually less than exact. This is something you were never quite happy about when having to provide information to guys firing artillery.
The demonstration MIDlet suite provided in this article would certainly have been handy to have running on a cell phone back in my military days. It simply allows the operator to push a button and record the device's (and presumably the user's) location and elevation (called a waypoint) along with a note/comment entered by the user. There are two MIDlets in the suite. The first MIDlet, called WayPointCollector, allows users to enter a note or comment about the waypoint to be collected and then marks the location obtained through the device with that note or comment. To run and test this MIDlet, you will need to use the EEG.
Once you have successfully loaded the project, run the MIDlet suite. When the emulator is started, you will need the External Event Generator up to provide location and elevation data to the MIDlet as if it was coming from the device. On the emulator window, select External Events from the MIDlet menu option at the top of the emulator. This will cause the EEG window to appear (see Figure 6).
|Figure 6. Starting the EEG: After starting the emulator (by running a project from WTK 2.3), you can start the External Event Generator window by selecting the MIDlet window and picking the External Events option. This should cause the EEG window to appear (as shown in Figure 4).|
Now, launch the WayPointCollector MIDlet. Enter a comment or note in the Way Point Note/Comment field on the emulator window and also enter a latitude, longitude, and altitude on the EEG window. Back on the emulator running the WayPointCollector MIDlet, you can now push the Mark Point button (see Figure 7). This will cause the MIDlet to collect location and altitude information from the EEG (as if it was coming from a real device) and, in this case, store the location and altitude information in a LocationStore (LocationStore is a device database and is another feature of the Location API) for later retrieval.
The second MIDlet in the suite, called WayPointLister, allows you to see the waypoints that were collected and stored by the WayPointCollector MIDlet. Run this MIDlet to see the waypoints you saved, with the location and altitude information obtained from thee EEG, in the devices Location Store (see Figure 8).
Figure 7. Collecting Location Data: MIDlets that need simulated geo-information while in testing, get it from the External Event Generator. In the case of this sample MIDlet, WayPointCollector stores the lat/long and altitude obtained from the EEG with the note/comment field when the Mark Point button is pressed.
Figure 8. The WayPointLister MIDlet is provided for completeness of the demonstration. It allows you to pull back the waypoints stored on the device and see that the lat/long and altitude information obtained via the EEG has been successfully saved.
The EEG window can also be used to run a script that changes the simulated geo-information provided to the emulator over time. This is particularly useful when building MIDlets that have location listeners constantly looking for and reacting to changes in location. The EEG scripts are actually quite easy to write as they are written in XML and consist of a set of waypoints that are read and fed to the emulator, as you require. A small script example is provided below:
<waypoint time="1500" latitude="14.389796708964603" longitude="50.09985002736201" altitude="310" />
<waypoint time="5500" latitude="14.390283327582706" longitude="50.099909292742595" altitude="310" />
<waypoint time="5500" latitude="14.390282428592135" longitude="50.100262519964886" altitude="310" />
<waypoint time="1500" latitude="14.390793552257932" longitude="50.10032395846041" altitude="310" />
WTK 2.3 comes with a nice demo application called CityGuide that demonstrates the use of a location script with the EEG.