Monday, 17 December 2007

Location based Java Micro Edition

My first encounter with location based services was in 2000 when working for a telco back when the internet bubble had not burst and life was good! Several months later the telco shelved the technology due to lack of enthousiasm of customers to pay for knowing where they were. And that is probably still the case today. Unless you are offering something fantastic (like on-board car navigation for example) nobody is going to pay for location based content.
Nonetheless the last year has seen a revival of location based chatter on the web and i don't seem to be able to escape from it. Last year we field tested location based java micro edition software on regular phones and bluetooth gps receivers. Then this year three seperate companies asked us help them with their location based software. All three were having difficulties with the technology so it's safe to say it's not as easy as some might portray.
First off, there is very little on the web in the way of working, open examples that you can take apart and examine. Countless sites have a code fragment that works for them, on their hardware. And then there were a bunch of authors who wrote about something they made in the Sun WTK emulator but never tested on a real phone. These 'look at me, my boss gave me time to read the tutorials and now i'm a guru' authors always annoy me because they always say things that are wildly wrong. For example at a local Java conference in the Netherlands there was someone lecturing on location based services who made the bold claim that 'Your mobile will determine which location based services are available and use them, so if you do not have a GPS receiver it will use the telecom networks positioning information. And yes you can actually use that right now!' not knowing that at the time there were no network operators that had that service switched on.

Anyway dragging myself back to the topic; part of the enthousiasm on the web has been due to the fact that a number of device manufacturers are starting to implement the location based API (JSR-179). It's been around for a while, but there used to be only two phones (guarded in finland by dragons) that had any sort of implementation. And needless to say they both had a different implementation all together. But Nokia and Sony Ericsson have been introducing enough models with a JSR-179 implementation to make it fairly widespread in the high-end segment of the phone market (in Europe anyway). This is a good development, but there are still a few problems with the Location API JSR-179 implementations:
  1. There are few phones that actually have an inbuilt method for location determination. The Nokia N95 must be the most popular, but most phones just do not have GPS hardware.
  2. The hardware that does have inbuilt GPS chips and antenna's tends to be exactly the hardware that is running an operating system that is hard to run java on. For example all the windows mobile devices that are popular for (among other things) in-car navigation. And what about all the Garmin, Becker and TomTom hardware that people are buying in busloads. Ever tried to run Java on one of those?
  3. A JSR-179 implementation dictates CLDC 1.1. So if you are developing for a number of devices here is another fragmentation issue. If you want your software to install on a CLDC 1.0 device (and there a tons of them) you cannot use JSR-179. So now you have two code-bases.
  4. The JSR-179 implementations are still new and therefore buggy. For example an implementation we tried automatically tried to search for GPS bluetooth devices the first time we tried it, but had no facility to change which GPS bluetooth device was selected. Great if you buy a new GPS receiver!

Generally speaking there are three strategies for getting location information in Java Micro Edition:

  1. Use the location API
  2. Use the bluetooth API (JSR-82) and bluetooth serial port protocol to read from a GPS bluetooth receiver.
  3. Use the serial port protocol to read from a COM port on the device.

Each strategy requires completely different code. I've tried em all, and they can all be done, but not on all hardware.

It's late... I'll get back to this soon.




3 comments:

hieuvan said...

Hi Robin,
This is such a good post.I'm doing the project in final year about location based social networking.Not talking about social networking but the location based aware.I got the code using location api to get coordinates from bluetooth GPS,can you upload the code for the other 2 ways using bluetooth api and serial port protocol or email to me at hieuvan177@gmail.com.Also, one more question,do you know how to run jsr179 on emulator on laptop because my code only works when running on mobile but i must test more code to get coordinates and send it to the server and then reverse-geocoding it to a location and return a map display the user's location on map.So i gotta run on laptop many times to make it work,i can not just write code and put in mobile without knowing it works or not and then fix the code again.
Thank you,
Hieu

Robin said...

Hi Hieu,
Been busy and only just got round to your post. Unfortunately i cannot post the code because my client owns the rights to it.
The Sun WTK 2.5 onwards supports JSR175 support. You can fill in coordinates and it fakes the location service.
To read a Bluetooth device there are two options. (1) rely on the location API. This generally works, but you get very little control over the connection. E.g. if you want to connect to a different device on many devices it is unclear how to proceed. (2) open a serial connection using the bluetooth serial protocol.
If you decide to use (2) the bluetooth serial protocol you first lookup the bluetooth address of the device (a kind of mac address for bluetooth) using the DiscoveryAgent class. You have to implement the DiscoveryListener interface to listen to discovery events. Once you have the bluetooth address of the GPS receiver your open a serial connection of this form:
btspp://xxxxxxxx:1;master=false;authenticate=false;encrypt=false where xxxxxxxx is the bluetooth address of your GPS device. Read off the serial connection every second or so and you will get NMEA sentences which you need to parse (google for NMEA parser code). It's not trivial.

Iwanna Know said...

Thank you for your blogs, they are great. I am a bit confused, however, on the midlets. I have been trying to get a gmail client for Windows mobile like what I have on my blackberry. I was able to install the IBM emulator and ran it successfully, but it doesn't seem to recognize the mail.jad from the google site and I cannot make it search for it where google likes to put it. Any ideas? I am thinking that i may be mixing platforms here, hence it is not installting or recognizing it.