dotMobimobiForgemobiReadyDeviceAtlasgoMobi
background image

Adding location to a non GPS phone: introducing CellID

Section Feature Image
Posted by tomsoft - 23 Sep 2008
Twitter share icon Facebook share icon Google Plus share icon

In this two part article (see part II here), we will introduce mobile positioning based on CellID, and we will take a look at OpenCellID, the open source database of CellIDs. We will demonstrate how to use OpenCellID through some simple examples. The second part of the article will show how to use OpenCellID with OpenStreetMap and the 8Motion library to create a full interactive mobile mapping experience in JavaME, with each of these examples being less than 100 lines of code.

What is CellID?

We all know that GPS will be deployed in the vast majority of phones in the future. For now though, only a few high-end handsets are GPS enabled. An alternative, which has been available for some time, but which has gained momentum only recently is location based on CellID. So, what is CellID? A CellID is a number which is associated with a specific cell (the radio tower to which your handset is connected). In most cases, this is the closest tower to your location. So by knowing the location of this tower, then you can know approximately where the handset is. This concept is illustrated below. However, a tower can cover a huge area, from a few hundred meters, in high density areas, to several kilometers in lower density areas. This is why location CellID accuracy is lower than GPS accuracy. Nevertheless location via CellID still presents a very useful alternative.

CellID has recently become much more popular, thanks mainly to its seamless integration into GoogleMaps for Mobile.

OpenCellID

So this sounds great, let's just get the device's CellID, and then we will know its location. So what's the catch? The issue is that the location of cells is not public information. Operators keep this private, for many reasons including:

  • They don’t want to give tower location information to their competitors
  • They use this as an extra revenue income, as they provide paying services to retrieve cell location
This is the reason we have set up a service called "OpenCellID". OpenCellID.org is an open source database of CellIDs, serving two purposes:
  • Anyone can create or use an application to gather information about cell locations, and send this information to the OpenCellID server, thereby improving the coverage
  • The database can be used by any application to retrieve the location of a cell, according to the CellID

How to use OpenCellID

The OpenCellID API is a simple REST API. There are only two relevant calls: measure/add and get/cell. Measure/add is used to add a measure of cell. This is used by any application that wants to add information to the database. Such applications produce content for the OpenCellID database. To make use of the API, a key is required for communication with OpenCellID.org. The key is used to track application providers, and to ensure that no fake data are inserted into the system. Examples:
http://www.opencellid.org/measure/add?key=myapikey&mnc=1&mcc=2&lac=200&cellid=234&lat=3.42&lon=3.12

Parameters:

  • myapikey: Substitute here the key that you received while registering at OpenCellID.
  • mcc: the mobile country code
  • mnc: the mobile network code
  • lat: lattitude
  • lon: longitude
  • cellid: CellID
  • lac: location area code

The URL request above will tell the server that a client found a cell of id 234, for mcc=1, mcc=2 and the lat,lon position of 3.42,3.12. A word of caution: all data should be submitted in decimal, while some handsets (SonyEricsson for instance) provide lac and cellid in hexadecimal, so you will need to convert them before calling the API.

Cell/get is used to get the position associated with a cell. For example:
http://www.opencellid.org/cell/get?mcc=250&mnc=99&cellid=29513&lac=0

You need to provide at least mcc, mnc (mobile country code, and mobile network code of the operator), and cellid. Lac (location area code) is an optional parameter, and will help to determine an alternate position if cell is not found. The API will return a simple XML document, like the one below:

<rsp stat="ok">
  <cell lat="57.8240013122559" lac="0" lon="28.00119972229" mcc="250" nbsamples="38" range="0" cellid="29513" mnc="99">
  </cell>
</rsp>

This can be interpreted simply as: lat and lon are the coordinates of the cell, based on 38 samples. If needed, you can use the optional parameter fmt to specify an output format e.g.:
http://www.opencellid.org/cell/get?mcc=250&mnc=99&cellid=29513&lac=0&fmt=txt
will return something like this:
57.8240013122559,28.00119972229,250,99,0,29513,100,38
This carries the same information as before, but in a much more compact form (see the API description for a complete description). Others APIs are under development, for instance to retrieve operators from mcc/mnc.

Sample program

So now let's use OpenCellID to create a small program, written in JavaME, which will just get the CellID from the phone, and obtain the device's location by making a request to the OpenCellID server and displaying the results.

First, let's get the CellID:
We use SonyEricsson specific properties. There properties are non standard, and only available on some devices.

  // These properties are implemented on latest SonyEricsson phones
  // This does not work on others (Nokia, etc...)
  String cellid=System.getProperty("com.sonyericsson.net.cellid");
  String mcc  = System.getProperty("com.sonyericsson.net.cmcc");
  String mnc  = System.getProperty("com.sonyericsson.net.cmnc");
  String lac  = System.getProperty("com.sonyericsson.net.lac");

Cellid is of course the CellID, mcc is the mobile country code, mnc is the mobile network code and identify the operator and the country (cmcc stands for current mcc). That's all we need to find our location. Then, verify if these properties are supported:

String info="This phone does not support CellID";
 
  if(cellid!=null) {
    info="Cell:"+cellid+" mcc:"+mcc+" mnc:"+mnc+" lac:"+lac;
    url="http://www.opencellid.org/cell/get?cellid="+Integer.parseInt(cellid,16)+"&mcc="+mcc+"&mnc="+mnc+"&lac="+Integer.parseInt(lac,16)+"&fmt=txt";
    cellInfo.setString(info);       
 
    Thread t=new Thread(this);
    t.start();
    posInfo.setString("Requesting position...");
}

In this part, we have created the URL to request information on the server, and start the fetch of the information in a separate thread:

  public void run(){
    try {
      HttpConnection cnx = (HttpConnection)Connector.open(url);
      InputStream is=cnx.openInputStream();
      StringBuffer b=new StringBuffer();
      int car;
      while( (car=is.read())!= -1){
        b.append((char)car);
      }
     is.close();
     cnx.close();
     String res=b.toString();
     if(res.startsWith("err")){
       posInfo.setString("Cell not found!");
     } else {
       int pos=res.indexOf(',');
       String lat=res.substring(0,pos);
       int pos2=res.indexOf(',',pos+1);
       String lon=res.substring(pos+1,pos2);
       posInfo.setString(lat+" "+lon);
    }
 } catch (IOException ex) {
      ex.printStackTrace();
      posInfo.setString(ex.toString());
  }
}

If the API call returns something starting with "err", we are probably in error. Otherwise, we will have our current CellID positioning.

And that's it done! The complete source code is available to download from opencellid.org.

So, what happens if the CellID is not in the database? Then the program will display an error. You can improve the accuracy of OpenCellID by discovering more cells.

The second part of this article, published here, will build on this first part, by creating an interactive program displaying the device location on a map, using the free J2MeMap component.


Posted by tomsoft - 23 Sep 2008

tomsoft's picture

Thomas Landspurg is the CEO of 8Motions, a company specialized in providing services and technologies for mobile geolocalized system. Thomas also runs the OpenCellID opensource project.
Thomas is also involved in the Webwag project, aming to provide Widgets on all our connected devices...

Previsouly, Thomas was CTO of In-Fusio where he leaded the devleopment which created the first and one of the most succesful mobile game engine.

Posted by fsa3 6 years ago

Is anyone aware of any plans for browsers to pass the proper information (cellid, lac, etc) as part of requests to webservers so that regular mobile websites can be location aware?

Posted by jeff06 6 years ago

For comments,...
On Future Nokia, those System properties should be available:
com.nokia.mid.networkid
com.nokia.mid.cellid

No news on LAC flag ...

BTW, Thomas your OpenCellID initiative is brilliant ! thinking of adding other bearer in ? (WIFI for example ...)

Posted by tomsoft 6 years ago

Hello Jeff,

Thanks for the feedback. Yes, I've been through this in fact, but did not find a Nokia phone yet where it works. It seems that access to these properties require the midlet to be signed. However, you will notice that the source sample check this already....

Regarding Wifi, good suggestion too. I think that there are other database existing, so best option would be to merge both databases, or use OpenCellID.org as a proxy to the Wifi database.

Posted by mederix 5 years ago

Hi,

In my Nokia N95 retorne NULL too.

Posted by Chethan Vasishta 5 years ago

When i try to retrieve the Cell id in nokia 3230.. using Cell-ID or com.nokia.cellid it shows null.. :(. Is there a generic way to retrieve the cell id?

Posted by ronanhigg 5 years ago

One browser is bringing cell-id to web pages: Internet Exporer. But it's done using Google Gears and only works on Windows Mobile PocketPC/Professional versions.

Google plans to get Gears Mobile onto all mobile browsers, and cell-ID sniffing along with it, but it will take quite some time.

Even "open" apple iPhone does not reveal cell id either to the iPhone Safari browser or to iPhone apps via the Core Location api.

In relation to Nokia 3230...it is an S40 non-symbian phone. It only runs Java midlets and the cell-ID is not available to java on this operating system...because Nokia sucks.

Posted by Parveen0312 3 years ago

Hello Sir,

Please tell me the cellid property for samsung mobiles

Posted by tspshikari 1 year ago

Hi,
I just wanted to know as you can get the lat long details by providing
the cell id and lac, is it possible to get cell id and lac from lat long if the mcc and mnc are known??