当两个locationManager对象调用requestLocationUpdates(...)时?
问题描述:
的代码是这样的:当两个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定位更慢?
答
您不必创建两个对象LocationManager。
用这种方式来获取所有可用的供应商,并从他们那里得到修复,并在onLocationChanged()
返回的修复将是更好的这的LocationManager可以得到。
List<String> providers = locationManager.getProviders(true);
for (String provider : providers) {
locationManager.requestLocationUpdates(provider, 0, 0, this);
}