android - 当两个locationManager对象调用requestLocationUpdates(...)时?

标签 android location locationmanager

代码是这样的:

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

关于android - 当两个locationManager对象调用requestLocationUpdates(...)时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9578262/

相关文章:

android - Robolectric 和 chrisbanes/ActionBar-PullToRefresh Activity 测试

android使用WIFI检测位置

android - 在执行期间向空 TableLayout 添加行

android - 如何在钛合金中向通知添加声音

安卓插件模式

android - 应用在启动时崩溃

swift - 隐藏节点不显示带有名称的子节点

java - Android Location getBearing() 总是返回 0

android - RequestLocationUpdates参数android

java - 无法让位置管理器在 Fragment 内工作