Good day!
Introduction
Today, geolocation services such as
GPS and
Cell ID have become an integral part of our life. Through them, we can find out where we are, for example, if we are lost, or just share our location on social networks, for example, on Foursquare.
Many J2ME mobile phones support the
Location API (
JSR-179 ). Using it, we can easily write some useful and, most importantly, interesting application for this platform.
In this article, I propose to consider the possibilities of the Location API for J2ME and write a small but very interesting application. But first things first.
What are geolocation services used for?
Geolocation services allow you to quickly answer three questions, namely:
- Where I am?
- What is around me?
- And how the hell did I get here?
')
For example, you feel very bad (pah-pah-pah), not a single passerby is by your side and you cannot say a word. You will be assisted by
GPS , which will provide the ambulance with the coordinates of your location. Unfortunately, this principle only works in the United States when calling 911.
Closer to the point
In order to use our application, we need a phone that will meet the following requirements:
- J2ME platform
- the presence of the phone JSR-179 ( Location API )
- CDC ( Connected Device Configuration ) or CLDC 1.1 ( Connected Limited Device Configuration Profile)
Such phones are, for example,
Nokia E71, E66, N95, N96, 6210 Navigator and many others ...
Device location
To determine the location of the device, the
Location API uses real-time positioning methods available to it. Accuracy depends on the methods used.
Usually, built-in
GPS devices are used that give us the necessary information, namely width, longitude and height.
The width is expressed as 0-90 degrees (north or south).
Longitude is expressed as 0-180 degrees (west or east).
The height is expressed, respectively, in meters above sea level.
Applications can use multiple positioning methods.
- Cell ID : when using this method, the value from the nearest cell tower, the so-called BTS ( Base Transceiver Station ), is taken as the location coordinates. The accuracy of this method depends on the range of the cell tower. For GSM networks, this distance varies from 2 to 20 kilometers.
- Using satellite: GPS or global positioning system using data received from one of 24 satellites in orbit. GPS determines your location, equal to the time difference of the passing signal from one satellite to another. GPS is the most accurate location indicator. The error will be about 4-40 meters (with a clear sky).
From theory to practice
JSR-179 is nothing more than a
javax.microedition.location package that is wired inside your mobile phone. It provides developers with the opportunity to develop geolocation services for
J2ME , providing all the necessary information (starting from the coordinates and ending with the storage for your marks).
The hardware platform determines which methods of real-time positioning are available to you at the moment. You absolutely do not need to worry about which method to use, because
J2ME will solve it for you. Accordingly, the most accurate method available (
GPS ,
Cell ID ) will be used.
To make sure that the
Location API is available, we can do the following:
... public boolean isLocationSupported() { boolean isItTrue = true; try { Class.forName("javax.microedition.location.Location"); } catch (Exception e) { isItTrue = false; } return isItTrue; } ...
So, go further
To write a geolocation application, we need to work with the following classes:
- Criteria , containing information about accuracy, response time from satellites or towers and speed.
- LocationProvider , which works with the data of the Criteria class to determine your location.
- Location An object containing the coordinates, speed (if available), address as text (if available), and the time over which the calculations were made.
- The coordinates themselves (yes, yes, I understand you) we can get from one of two classes ( Coordinates or Qualified Coordinates , to choose from). The only difference is that QualifiedCoordinates provides additional data on the measurement accuracy, presented in meters.
For the concept and consolidation of the theory, I propose to write us a small
MIDlet (this is the name of the J2ME application):
So in a couple of minutes you wrote an application that determines the width, longitude and height, which is currently redundant, of our location.
The purpose of this topic was to introduce you to the topic of building geolocation services, which was done. If you want to read the full
Location API ,
please .
PS Unfortunately, I am far away from the desktop PC to compile the source code and show you screenshots that I promise to do later .