Getting Coordinates

Getting Coordinates

Where am I? – The basic Location Question

It is the most basic and the most important question in a Location Based Service application. The ultimate motive of the user might be to drive to a place, visit a monument, track his friends or relax in the nearest cafeteria. But the problem always starts with where a particular person (rather a device) is?

Coordinate Alert Program

This program pops an alert message showing your current location. You need to be familiar with basic LCD UI for this and the following programs. If you do not already know about it, first learn about basic LCD UI and come back.

Create a new project named ‘CoordinateAlert’ and the MIDlet class name same as that of the project. In the source folder place Build and run the program. Note that in the device drop-down list, you need to select ‘Nokia Prototype SDK’ or any other SDK that supports the location API else you will get compilation error while building the project.

Now let’s understand the code. We will concentrate on the givePositionAlert() function, the rest of it is simple j2me. The essence of the location extraction is in the following lines –

Criteria cr = new Criteria();
LocationProvider lp = LocationProvider.getInstance(cr);
Location l = lp.getLocation(60);
Coordinates c = l.getQualifiedCoordinates();

To get the co-ordinates of current location we basically follow three logical steps –

  1. Set the criteria of the location provider
  2. Get the location provider instance according to set criteria
  3. Get the location object from the location provider
  4. Get the co-ordinates from the returned location object




It contains all information of a location e.g. the co-ordinates, time stamp at which it was measured, speed etc. Methods can be invoked on the object to get the data. Sometimes the location returned by the provider might be invalid. The isValid() method can be called to check for its validity.

Coordinates and QualifiedCoordinates

Other Notes of this Program

Limitations of this Program

Want to do it smarter? Let’s go to the next part!