I have problems with location systems. I have a service that implements a locationlistener. I want to get the best location using the network, when possible, gps if the network is not accurate enough (accuracy above 300 mt). The problem is this. I need a place (more precisely, if possible, inaccurately different) every 5 minutes. I start with:
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 an accuracy of more than 300 meters, I want to go to the gps location system.
If I remove allupdates and then request gps updates, for example:
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); }
the system stops waiting for gpsupdate, and if I enter the nearest room, it can remain without location updates for several hours, ignoring the timeupdate. Is there a way to tell the locationprovider to switch to the network if gps doesn't indicate the location in “x” seconds? Or how to understand when gps is not localized?
or if request requestlocationupdates from 2 providers at the same time (network and gps) can be a problem?
Any suggestion?