More than one location provider at same time
Posted
by
Rabarama
on Stack Overflow
See other posts from Stack Overflow
or by Rabarama
Published on 2012-03-20T11:20:08Z
Indexed on
2012/03/20
11:30 UTC
Read the original article
Hit count: 424
I have some problems with location systems. I have a service that implements locationlistener. I want to get the best location using network when possible, gps if network is not enough accurate (accuracy greater than 300mt). The problem is this. I need location (accurate if possible, inaccuarte otherways) every 5 minutes. I start with a :
LocationManager lm=(LocationManager)getApplicationContext().getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
String provider=lm.getBestProvider(criteria, true);
if(provider!=null){
lm.requestLocationUpdates( provider,5*60*1000,0,this);
In "onLocationChanged" i listen to locations and when i get a location with accuracy greater than 300mt, i want to change to gps location system.
If I remove allupdates and then request for gps updates, like this:
lm.removeUpdates((android.location.LocationListener) this);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
String provider=lm.getBestProvider(criteria, true);
if(provider!=null){
lm.requestLocationUpdates( provider,5*60*1000,0,this);
}
system stops waiting for gpsupdate, and if i'm in a close room it can stay without location updates for hours, ignoring timeupdate indications. Is there a way to tell locationprovider to switch to network if gps is not giving a location in "x" seconds? or how to understand when gps is not localizing?
or if i requestlocationupdates from 2 providers at same time (network and gps), can be a problem?
Any suggestion?
© Stack Overflow or respective owner