Location services in JavaTM ME

Location API overview

The Location API for JavaTM 2 Platform, Micro Edition (J2METM) (JSR-179), first introduced in S60 and Series 40 3rd Edition, is an optional package that can be used with many Java ME profiles. The minimum platform for JSR-179 use is Connected Limited Device Configuration (CLDC) 1.1, because the API requires floating point math support.

The Location API is supported in S60 and Series 40 with clarifications detailed in the Location API for J2METM (JSR-179): Implementation Notes.

The purpose of the Location API is to enable the development of location-based mobile applications. Considering the nature of mobile devices, the Location API provides a natural way to utilize location-based information. Moreover, the Location API is a compact package of classes and interfaces that are easy to use. The three main features that the Location API brings to mobile programming are:

  • Obtaining information about the location of a device

  • The possibility to create, edit, store, and retrieve landmarks

  • The possibility to obtain the orientation of a device

The Location API needs a connection to a location-providing method, which generates the locations. Location-providing methods differ from each other in many ways. For example, the use of some methods may cost more than others, and the accuracies supported by individual location-providing methods vary. The most common methods are device-based (for example, GPS module - a method based on a Global Positioning System's satellites), network-based (for example, cell of origin - a method in which the network determines a user's place), or hybrid methods (for example, A-GPS - a GPS method which also uses network-based information to speed up location determination).

The figure below shows a generalized structure of a Location API MIDlet that uses a GPS module as a location-providing method. After the MIDlet is found to be working properly in the SDK environment, it should also be tested under real-world conditions. Typically, real-world testing means the outdoor use of the MIDlet in a device that supports the Location API.

Figure 159: General Location API MIDlet model

Main use cases

Location-Based Services (LBS) are applications that utilize a user’s current physical location to provide enhanced services. You can use location information for a variety of purposes. The use cases include:

  • Mapping, navigation, and directions applications, which can also be combined with directory services

  • Workforce-tracking and management applications

  • Interactive gaming and services that complement sporting events, concerts, and more

  • “Finder” applications can apply users’ location to help them locate people or places nearby

  • Weather applications can provide local forecasts and warnings about bad weather.

Geographic Coordinate System

A basic knowledge of geographic coordinates is required before starting to code with JSR-179. The Location API uses coordinates that are given using the World Geodetic System (WGS 84) datum. It is also currently used as a reference system by the Global Positioning System (GPS).

The coordinates in the API are constructed from latitude, longitude, and altitude values. (In this case, altitude is the elevation above the sea level.) In the below Figure the horizontal lines measure latitude. These lines represent the north-south position between the poles. The North Pole is 90 degrees North (+90 degrees) and the South Pole is 90 degrees South (-90 degrees). The largest circle is called the Equator and is defined as 0 degrees. Locations above the Equator have positive latitudes (0 to +90 degrees) and locations below the Equator have negative ones (0 to -90 degrees).

However, the definition of the North Pole is not unambiguous. Location API implementations may use either the Magnetic North Pole or the True North Pole (also known as Geographical North Pole). In practice, any application using a compass should check how the API defines the North Pole.

Magnetic North Pole is the point to which magnetic compasses point. The position of the Magnetic North Pole is not static, since its position moves several kilometers a year. Poles are not at directly opposite positions of the globe, because they move independently of each other. The definition of the True North Pole defines latitude as +90 degrees. The distance from the North Pole to the Equator is approximately equal to the distance from the South Pole to the Equator.

The lines drawn from north to south in the below Figure are meridians, which are constant longitudinal values. There is no natural starting position for longitude, which is why a reference meridian had to be chosen. Traditionally the Prime Meridian is the meridian that passes through the Greenwich Observatory (located in Greenwich, England). The value of the Prime Meridian (Greenwich Meridian) is 0 degrees. WGS84, which the Location API uses, defines its zero meridian about 100 meters east of the traditional one. Locations east of the prime meridian have positive longitudinal values (0 to +180 degrees). Locations west of the prime meridian have negative longitudinal values (0 to -180 degrees).

Figure 160: A globe showing longitudinal and latitudinal lines. The Zero Meridian and Equator are drawn in bold.

As seen in the figure below, the latitude lines become smaller and smaller near the poles. At the equator, one degree of longitude is roughly 111.3 km, whereas at 60 degrees of latitude one degree of longitude is only 55.8 km. That makes it difficult to see the lengths of latitudinal lines.

Figure 161: Length difference between latitude lines on the equator and at 60 degrees of latitude

Development Environment

Location API-based applications can be developed and tested in a simulated environment. For example, the S60 3rd Edition, FP 1 SDK can be used to simulate a route from a location to another in a Location API MIDlet. Application testing in the simulated environment requires location data. Test data can be created in a number of ways. One way is to use the Route tool that is provided, for example, with Series 60 3rd Edition, Feature Pack 1, for MIDP (available through prefs.exe). In the Route tool you can paint your route and save it on NMEA 0183 format for your MIDlet's usage. The NMEA (National Marine Electronics Association) 0183 format is a standard that is commonly used in GPS data transmission.

To change the coordinates of a route area, enter the new coordinates (either using the "N", "S" notation or by using negative and positive values) to the top, left, bottom, and right edit fields and click the Load scale button. The new coordinates are displayed above the drawing area. Loading a new scale deletes all existing coordinates in the route, since scaling them would easily cause confusion. When the route is finished you can save it by clicking the Save Button. Clicking the Apply button allows the SDKs to use the new route you have painted. The figure below shows an example screen shot of the Route tool in use.

Figure 162: Location route tool