Brian Li
Brian Li

Reputation: 43

When two locationManager objects call requestLocationUpdates(...)?

The code is like this :

private LocationManager locationManager1;
private LocationManager locationManager2;    
......
locationManager1 =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager2 =(LocationManager)getSystemService(Context.LOCATION_SERVICE);    
....
locationManager1.requestLocationUpdates("GPS",30000, 0, LbsClient2ServerDemo.this);

locationManager2.requestLocationUpdates("GPS",0, 0, LbsClient2ServerDemo.this);    
......

When two locationManager objects call requestLocationUpdates(...) , locationManager1 and locationManager2 have the GPS providers.

The locationManager1 object is searching the satellites now , but the locationManager2 is coming , will the locationManager2.requestLocationUpdates() interrupt the locationManager1 ? Maybe will it cause the GPS location much more slowly?

Upvotes: 2

Views: 637

Answers (1)

Hesham Saeed
Hesham Saeed

Reputation: 5378

You don't have to create two objects of LocationManager.

Use this way to get all available providers and get fixes from them, and the fixes returned in onLocationChanged() will be the better which LocationManager can get.

List<String> providers = locationManager.getProviders(true);
for (String provider : providers) {
    locationManager.requestLocationUpdates(provider, 0, 0, this);
}

Upvotes: 2

Related Questions