问题
if (gps_enabled)
_locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
if (network_enabled)
_locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
Condition:
- You are in the building where you have wifi connection, but no GPS signal.
Result:
This works when Setting->"Use wireless networks" is on and "Use GPS satellites" is off. However, when both are checked, above code sometimes works (through network) but sometimes times out trying to get location from GPS.
I tested on nexus one.
来源:https://stackoverflow.com/questions/4455802/android-if-both-gps-network-are-requested-at-the-same-time-network-provider