Getting that to work was no picnic, though.
Here's a basic overview of how it's supposed to work:
- choose a list of things you want from your GPS device and set it all up in a Criteria object
- instantiate a LocationProvider by calling LocationProvider.getInstance(myCriteriaObject);
- periodically ask for a new location by calling provider.getLocation(timeout)
- 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.
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();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.
provider = LocationProvider.getInstance(c);