The Power Of Location Is Changing How Business Is Done! Learn More Here!

Location Based Services

Subscribe to Location Based Services: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Location Based Services: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

LBS Authors: Liz McMillan, RealWire News Distribution, Kevin Benedict, Shelly Palmer

Related Topics: Java Developer Magazine, Open Web Magazine, Location Based Services

Java Developer : Article

The Java Location API

Where do you like your coffee?

Location-based technologies are coming, but without applications they'll be going nowhere. We take a look at JSR 179, the Java API for location services, and see what it has to offer.

It's Saturday afternoon and Melanie is shopping. She's wondering if any of her friends are in the mall. Melanie pulls out her Java-enabled phone and starts up her friend finder application. The application detects that Marcia and Bill are in the same area. Melanie sends them each a text message asking if they want to meet for coffee. They end up getting together for a cappuccino and having a lot of fun.

These types of innovative location-aware applications are available today. They are simple to use but extremely complex to implement. There are many considerations, including privacy, security, handset features, network capabilities, and coverage. Standards help to facilitate these applications by providing well-known contracts for functionality and service. This article will explore the use of Java Location API - JSR 179 - when it becomes part of the available packages for developers.

Location Determination
Determining the coordinates of a subscriber is dependent on an underlying technology known as Position Determining Equipment (PDE). This technology ranges from Global Positioning Systems (GPS) to network triangulation algorithms that use cell tower location and signalling characteristics. Depending on the PDE and current conditions, the accuracy can vary between 10 and 16,000 meters.

Hardware receiver costs have decreased to the point that the use of GPS technology is becoming common for location-based services (LBS). GPS involves three or more satellites and the concepts of triangulation. For a number of years, GPS units have been used for outdoor wilderness activities and they have become increasingly sophisticated, featuring fairly detailed maps. In-vehicle navigational systems that use GPS are also quite commonplace and are helpful for automobile drivers in unfamiliar locations. A number of cellphone manufacturers are including GPS chip sets in their handsets, making it possible to get a location from the handset without any assistance from the wireless carrier. However, keeping the GPS turned on to achieve accurate and quick determination of location is a battery drain for small devices. By providing an initial location using a cell tower/antenna to assist with the determination of location information, battery drain is reduced. The use of cell tower/antenna location determination is also the basis for the assisted GPS discussed below.

The simplest way for a wireless carrier to determine the location of a mobile caller is to use the location of the cell antenna handling the call. In rural areas, location determination is not very accurate, but in a dense urban area where cell towers are used to hold the antennae, location determination can be narrowed down to a few city blocks. This accuracy can be fine for simple LBS applications such as weather or local events. Where more accuracy is necessary, knowing the cell antennae coverage areas enables the LBS application to provide lists of landmarks, street intersection information, or highway exit information for the user to refine his or her position.

The Java Location API provides a PDE-independent interface for determining the mobile handset user's location. This API works within the context of the MIDP 2.0 security framework to ensure the subscriber's privacy. The underlying platform must support floating point numbers to represent real-world coordinates; for this reason, the API is built on top of the Connected Limited Device Configuration (CLDC). Rounding out the functionality of this API is the capability to acquire orientation through a compass as well as 3D pitch and roll.

Using the Java Location API
The LocationProvider class is the starting point for applications wanting to use the Java Location API. This factory class creates an instance based on some specified criteria for accuracy, power consumption, location synonyms, and cost.

try {
	//Use Low power mode
Criteria crit = new Criteria();

	// Instantiate a location provider
	LocationProvider locp = LocationProvider.getInstance(crit);

	// Get a location fix
	Location loc = locp.getLocation(30);
	Coordinates xy = loc.getQualifiedCoordinates();

} catch (LocationException e) {
	// location unavailable

In this example, the LocationProvider instance will block for 30 seconds while attempting to get the current position. If successful, an instance of the class location is created. The location class is a container for coordinate data as well as address information. A coordinate pair can be snapped to a street segment and a location synonym such as a provided address.

In many situations, it's desirable to continually position and notify the application via periodic updates. This can be accomplished by using the LocationListener class, as it receives location events at a specified interval.

The Java Location API provides the ability to store and retrieve locations on the handset. These locations are known as landmarks. They contain the coordinates as well as a name and description. Landmarks can be accessed by any Java application on the handset. It is possible to group landmarks by category - for example, restaurants or golf courses.

try {
	// get some golf courses
	LandmarkStore lms = LandmarkStore.getInstance(null);

	Enumeration enum = lms.getLandmarks("Golf Courses",null);

} catch (LandmarkException e) {
	// location unavailable

Privacy is an integral part of location-aware applications. This location information is subject to policies defined by the subscriber. The Java location API is reliant on the MIDP 2.0 security framework. The specification details permission names and the methods that are protected. For example, the permission javax.microedition.location.Location is used to protect the methods LocationProvider.getLocation() and locationProvider.setLocationListener().

An application using the Java Location API needs to take into account issues related to the network. One consideration is the network coverage, which can be either temporarily out of service or not available at all. Another important consideration is the amount of time required to get a location fix. It is not uncommon for this process to take between 5 and 30 seconds and this is dependent on the application's requirement for accuracy.

A weather forecast application, enhanced to use JSR 179, is able to use an accuracy based on cell of origin. This application would take the position, translate it into a postal code, and then request the forecast from the weather service. This type of processing is relatively lightweight and provides useful information to the subscriber.

A delivery application that's enhanced to use the Java Location API requires high accuracy for point-to-point driving directions. This application takes the target address and converts it to a coordinate pair. It then acquires the subscriber's position and may use a technique known as location refinement to snap to a well-known coordinate pair. For example, the subscriber may be prompted with street intersections and asked to identify his or her precise location. With these locations, it is possible to use advanced routing services to provide the driving directions.

Location Applied
The inclusion of location often increases productivity in enterprise applications. For example, a dispatch center could manage field staff more effectively by incorporating the real-time position of the personnel. The Java Location API enables new kinds of mobile services and enhances existing services.

Where to Learn More

  • JSR 179:
  • Open Mobile Alliance:
  • Open Location Services:
  • More Stories By George Moon

    George Moon is group vice president, R&D, and chief technology officer at MapInfo Corporation. His office focuses on standards and their development impacts, public technology briefings, and precommercial development and investigation of advanced technology. George has more than 25 years' experience with complex, multiuser, spatial information systems.

    More Stories By Will Wilbrink

    Will Wilbrink is the Java solutions architect at MapInfo Corporation.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.