是否有必要为Google Maps使用LocationManager.requestLocationUpdates和LocationManager.removeUpdates()?

时间:2016-11-28 23:12:14

标签: android google-maps geolocation google-maps-android-api-2

我使用GoogleMapView创建了一个应用。为了减少电池消耗,我想在应用程序未打开时停止位置请求。我发现这可以通过LocationManager完成。例如:

@Override
public void onPause() {
    locationManager.removeUpdates(this);
    super.onPause();
}

@Override
public void onResume() {
    locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), minUpdateTime, minUpdateDistance, this, null);
    super.onResume();
}

但目前我根本没有使用LocationManager,GoogleMapsView仍设法获取当前位置。我只需要在mMap.setMyLocationEnabled(true);函数中调用OnMapReadyCallback()。因此,似乎GoogleMapsView实现了自己的一种LocationManager,导致了这个问题,如果有必要创建一个LocationManager,只是为了告诉它在应用关闭时停止更新,或者是否足以调用mMap.setMyLocationEnabled(false);在我的onPause()函数中?

0 个答案:

没有答案