2012-03-06 73 views
2

的代碼是這樣的:當兩個locationManager對象調用requestLocationUpdates(...)時?

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);  
...... 

當兩個物體的LocationManager打電話requestLocationUpdates(...), locationManager1和locationManager2具備GPS提供商。

locationManager1對象正在搜索衛星,但是locationManager2即將到來,locationManager2.requestLocationUpdates()是否會中斷locationManager1?也許會導致GPS定位更慢?

回答

2

您不必創建兩個對象LocationManager

用這種方式來獲取所有可用的供應商,並從他們那裏得到修復,並在onLocationChanged()返回的修復將是更好的這的LocationManager可以得到。

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