October 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Using Location-Enabled MIDlets for Mobile Navigation

  • June 17, 2009
  • By Jayasurya Venugopalan
  • Send Email »
  • More Articles »

Implementing the MIDlet

Every MIDlet must have a startApp() method to initialize the MIDlet application, a pauseApp() method to pause it, and a destroyApp() method to terminate the MIDlet. The class SVGMidlet extends the MIDlet class and implements a CommandListener interface.

In the startapp() method of the MIDlet in this example, you instantiate a TextBox and pass it when creating a new instance of the Location object, LocPos. This TextBox is used to display the current latitude, longitude, and time of the mobile device. Then the back command is added to the TextBox.

A new thread is started with the LocPos object in a try/catch construct. This thread will constantly update the TextBox with the current latitude and longitude, as well as the time stamp.

Next, the main MIDlet menu items are generated by getList(). The main menu has three items:
  • Get Location: When invoked, Get Location displays the TextBox with the current location and the time constantly updated.
  • See Campus: See Campus is for seeing the map of the campus and the user's position, as well as the zoom in/zoom out and translation features.
  • Exit: Exit is for exiting from the MIDlet.

The getList() method returns a list of these three items. In the startApp() method, disp.setCurrent(getList()) will display the list of three items by making the Displayable List object the current display on the screen. If GetLocation is invoked, the listAction() method will set the current display to the TextBox and display the location and time with date.

If the user selects See Campus, the corresponding listAction() code will be invoked. This code will start a new SVGStatic Canvas thread, which will get its position updated from the LocPos thread, and implement the zoom and translation features in the campus map used.

If the user exits from the See Campus function, then the SVGStatic Canvas thread is made null before going back to the main menu of the three items (Get Location, See Campus, and Exit).

The pauseApp() and destroyapp() methods are left blank, but you can incorporate any functionality as needed.

Listing 3 (SVGMidlet.java) provides insight into the implementation of the main MIDlet for invoking and controlling the location monitoring as well as the campus navigation operations.

Running the MIDlet

First, it is important to find out the maximum and minimum longitude and the maximum and minimum latitude of the campus where the mobile location-enabled MIDlet will be used. These values are stored in the code, as indicated in Listing 2 (SVGStaticCanvas.java), in the variables minlong, maxlong, minlat, and maxlat, respectively.

One way of displaying the campus is to correspond the top of the mobile screen to north, the bottom to south, the right to east, and the left to west. Another way is to display west on top, east below, north on the right, and south on the left, with the top-left corner corresponding to the X and Y coordinates (0,0).

For example, consider a device screen that is 240 pixels wide and 340 pixels tall. Having north correspond to the top of the screen would mean that when the latitude is at its maximum (say, for example, maxlat is 82.245 degrees), the position will be on the line at top of the screen and ycoord = 0. So as the user moves south toward lower latitudes, the position will shift downwards and ycoord will increase up to a maximum of 320. Similarly, as the user moves eastward from left to right and the longitude increases, the x coordinate will also increase from 0 to 240.

The second approach (keeping west on top, east on bottom, north on the right, and south on the left) is very simple. As the user moves down (eastward), the longitude increases and the y coordinate also increases. As the user moves from left to right (northward), the latitude increases and so does the x coordinate.

Remember that in the Southern Hemisphere as the user moves northward, the latitude will decrease. See the two diagrams below.



Click here for larger image

Figure 4. Mobile Screen Orientation for West on Top and East Below



Click here for larger image

Figure 5. Mobile Screen Orientation for North on Top and South Below

About the Author

Jayasurya Venugopalan has 29 years of industry and academic experience. He works as a Senior Consultant at Wipro Technologies, Bangalore specializing in networking, network management, and NGOSS.





Page 4 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel