Monday, March 15, 2010

My mistakes to the J2ME Location API

Last week when I tried to test the location API for J2ME devices, I made big mistakes.
The 2 devices I tested are: NOKIA N93 and BlackBerry 8320. Actually I don't have any experience for J2ME location API before.Before testing, I checked the spec of these two devices, they both support Location API - JSR 179, so I thought they both have GPS receiver,but when I tested several location applications on theses two devices and even simple demos, none of them works on either devices: N93 keep looking for Blue tooth devices, and then pop up Location exception or pop up timeout exception; while the applications in blackberry keep hanging no response.

I spent the whole afternoon trying to make them works, but no luck. Finally I googled them again, then I found that these two devices do not have internal GPS receiver! They support location API means they need external blue tooth GPS receiver!!! Which explains why N93 keeps looking for blue tooth devices.

So I learned that even if a device supports Location API does not means it has GPS, then it means there is no way to check a device supports GPS or not via programmatic way, because it is impossible to distinguish if a device has built-in GPS with a device without GPS.

A solution for non GPS Blackberry devices
Another reason I made the mistakes is because I saw the Google Map works perfectly in my 8320 devices. Now I understand it might use cell id to get the location information.This will give the developer another hint to enable the loation service to the non GPS blackberry phones.

I found a open source project: OpenCellId, which maintain a cell id database, so you can query your location by providing your device's cell id.
Here is the API.

I checked the BlackBerry API, it has a GPRSInfo class, which provides the GPRSCellInfo class, GPRSCellInfo contains all the cell id information you have.
You can use the following code snippet to get the cell id:
   import net.rim.device.api.system.GPRSInfo;
   int cellId = GPRSInfo.getCellInfo().getCellId();
You can also get MNC, MCC, LAC, RAC etc.
With these information, you can use OpenCellId to retrieve your location.

This sounds interesting, I haven't try it yet, I am sure I will check it in future.