[Galaxy S I9000 General] bitbang3r:
I've been struggling with GPS/Location issues for the past 2 weeks learning how to program with them (Hero, but watching this forum bc I'll have an Epic4g soon). I've come to the conclusion that a large part of the problem with location and Android phones in general is the fact that most/all Android phones seem to do it the worst & most naive way possible. Meaning, they treat GPS like an abstract part of a desktop PC and do nothing whatsoever to try and take advantage of the optimizations that are now commonplace with other platforms.

Case in point: ephemera data. This is the data broadcast by the satellites that basically tells the phone, "here's where I was at x:xx, and here's where I'm going". It has a lifespan of a few hours. Normally, the ephemera data for ALL satellites gets broadcast by ALL satellites every 30 seconds, and takes ~6 seconds to download completely -- assuming the satellite has a strong (20dB or better) and error-free signal, which will almost never happen indoors.

In the WinMo world, it seems to be the norm for phones (HTC ones, at least) to forget about the satellites as a source of ephemera data, and just grab it over the internet instead (the same ephemera data is transmitted by all satellites, so it really doesn't matter where you get it from). That way, you can get it the instant you need it, without having to wait for the next ephemera broadcast to begin and complete successfully. As far as I can tell, most Android GPS HALs are smart enough to at least buffer the ephemera data, but NONE will try and use ephemera from anywhere besides a satellite.

Likewise, the signal strength you need and the time it takes to lock on partly depend upon how much you already know about where you are. If a GPS subsystem has no clue where it is, it takes a lot of satellites with strong signals and/or a long time for it to figure out where it is, because it has to look for data from all known satellites. On the other hand, if the HAL (thinks it) knows where it is, it can forget about even looking for satellites that are on the other side of the earth, and mostly forget about satellites likely to be out of range anyway.

This seems to be one area where Android HAL implementations are all over the place. Some seem to stupidly dump everything they know about their location at the drop of a hat. Most seem to be smart enough to buffer it for at least an hour or two, on the theory that your location isn't likely to change radically in a short period of time unless you're an extreme edge case with access to a military jet.

As far as I can tell, NO current Android HAL is smart enough to ask the network for a quick 'n dirty fix first. I suspect this is mostly due to Linux kernel architecture, which frowns upon closely-coupling technically-unrelated modules (like one dealing with networking and one reading data from satellites). The abstraction makes desktop PCs more interoperable, but contributes to the mess we have right now with Android location services -- slow GPS fixes, insane power consumption, and poor overall usability.

What needs to be done is for someone with a rooted kernel to basically rewrite the GPS HAL to incorporate the best of everything that's been done up to this point -- grabbing ephemera data from terrestrial source over the internet, taking advantage of network location to get a quick fix that can be quickly refined by GPS, and possibly incorporate a bit more "situational awareness" of the signal. IE, an algorithm something like the following:

Power up the GPS into a minimal state, and "sniff the air" to quickly determine whether there's a viable signal. If not, power down and forget about it. Watch the phone's other sensors. If the accelerometer doesn't indicate movement, it's probably pointless to keep aggressively trying to get a GPS fix. If the accelerometer suggests the phone is in motion, try sniffing the air for a usable GPS signal occasionally. If the light sensor indicates a sudden increase, power up GPS *instantly* and try to get a quick telemetry reading, because it might mean the user is now near a window... but won't necessarily be there for long.

Right now, the API itself is fairly simplistic and naive. Suppose I request updates every 6 hours to conserve power. From what I've seen on my Hero, it will dutifully wait 6 hours... then completely run down the battery aggressively trying in vain to get a GPS fix while the phone sits on my desk at the office. I might very well have been in full view of the open sky for an hour at lunch, but it wouldn't matter because it didn't even bother to check. In other words, it has no concept of taking advantage of opportunity when it can, and no common sense to give up when it's hopeless.

There's also the matter of wi-fi. Statistically, your phone is going to spend at least 30% of its time "at home", where you probably have an access point. What easier way to pinpoint location as "home" than to just spawn a thread to try and hail it while another one works on getting a satellite fix? The problem is, most (American, at least) Android owners end up disabling wi-fi, because Android (stupidly/naively) insists on trying to use wi-fi to the exclusion of 3/4G data under all circumstances, even if the wi-fi signal is poor and the 3/4G signal is flawless.

What's needed is a way for users to indicate to Android, "It's ok to power up wi-fi and use it to survey for SSIDs and/or try to hail a specific access point... just don't use it for actual networking". I suspect this will be a major uphill battle to get into an official release of Android, but would be a fairly trivial hack for rooted builds. Over time, a smart location integration service could build up its own local database of SSIDs seen at locations where you seem to spend a lot of time, and use them to get an even quicker fix when some app wants to know where you are.

I think part of it comes down to the carriers. In the US, at least, they were all happy about being able to hit users for another $5-12/month for "navigation service" a couple of years ago. None of them were happy about phones with onboard GPS. I suspect that the sad state of Android GPS is partly due to that as well... the carriers are the real customers of HTC, Samsung, Motorola, etc, and THEY really don't CARE whether the onboard GPS works well. And if they DO care, it's because they want it to suck as badly as possible, so customers can be persuaded to pay for "value-added" enhanced services. So, the manufacturers basically slap a GPS HAL onto their hardware that doesn't rock the Linux boat or even try to be innovative. The carriers get a selling point to check off, and the manufacturers save on development costs.

IMHO, the way Android phones handle location services are the next great XDA Developers goldrush to improve for rooted phones, mainly because right now there's so much ROOM for improvement.