December 5, 2008

internal affairs filed under JSR179

OpenWIG 0.3.07 is out and it supports JSR-179 style "Location Providers" a.k.a. internal GPS.

Getting that to work was no picnic, though.

Here's a basic overview of how it's supposed to work:
  1. choose a list of things you want from your GPS device and set it all up in a Criteria object
  2. instantiate a LocationProvider by calling LocationProvider.getInstance(myCriteriaObject);
  3. periodically ask for a new location by calling provider.getLocation(timeout)
  4. or implement a LocationListener interface, and register that with the provider. You can then specify some refresh intervals and timeouts and whatnot. Fortunately, you can also leave it on default values.
Sounds rather easy, no?
Well, yes, but with a caveat: there's no listProviders or equivalent method. If the phone has more than one provider, it can return pretty much anything it wants.
And it turns out that e.g. Nokia N95 has more than one provider, and one of them is very dumb and coincidentally that's the one that is selected when you specify "empty" criteria (the default Criteria instance means basically "anything will do")

It seems to work when you say that you want to get speed, course, altitude and you allow it to cost money:
Criteria c = new Criteria();
provider = LocationProvider.getInstance(c);
Oh and then there's the fun with invalid locations that can either have isValid flag set to false or be null. But that is easy to get right. Finding out that a phone is giving you a bad provider is the real pain.


sk750 said...

Thank you very much for this post!

It helped me to fix an issue with JSR-179 for Nokia E90 users with GpsMid quickly. :)


A said...

will shut down the application on Samsung SGH-I550, I560, and mayme other phones also.
You have to try to create provider with your settings and then (if you didn't receive valid provider) you have to create provider with limited criteria (without speed-course and with pover usage MAXIMUM). In such case you have to compute speed/course from GPS data in your code...

matejcik said...

A: thanks, good to know. i've opened an issue for this in my issuetracker, so if i ever get a hold of gps-enabled samsung phone, i'll fix it.

A said...

Just another comment: I recommend to specify setPreferredPowerConsumption( POWER_USAGE_HIGH ).
Speed of GPS startup may be significantly better with this.
For example on Nokia 6110Navigator: with POWER_USAGE_LOW, GPS is starting for about 60-150 seconds. With POWER_USAGE_HIGH you'll get the first fix in 10-20 seconds.