The Location API
In theory the Location API is the ideal solution for getting location information in a java program. A working demo with source code is included with the Sun Wireless toolkit (from version 2.5 onwards). You can deploy the demo on a real phone and chances are it will work. But here come the nasty details:
- The location API is not implemented on the majority of devices.
- If you are thinking of determining at runtime whether you can use the Location API: in most cases you cannot, because the Location API requires CLDC1.1, whereas a large number of devices have CLDC1.0. So you cannot compile an application for CLDC1.0 with Location API references and even if you could, it would not deploy.
- Location API implementations are of mixed quality. Devices i have seen with inbuilt GPS receivers such as the Nokia N95 tend to have good implentations. But most implementations default to looking for a Bluetooth GPS device. This is reasonable since Bluetooth GPS receivers are cheap and abundant. However the way in which the Location API handles communication with a Bluetooth device can not be influenced by a java application. For example once a GPS device is selected it tends to stay selected. There is no user interface or API for unselecting it or selecting another device. Another example is how the location API handles connection problems. Should it use a timeout in the event a gps device sends rubbish or is turned off and if so how long should the timeout be? Should it try to reconnect? If you use the Location API you will have no control over these matters. Most likely the only advice you can offer users with problems is; reset your phone and try again please (because we don't know what your phone is doing)!
So unless your target devices are ultra modern smartphones with inbuilt gps receivers it is best to give the location API a wide berth for the moment. So that leaves you with two options for developing location based applications; Bluetooth and Com port.
Coming next ... the wonderful world of Bluetooth communication in Java Micro Edition