MyLocationOverlay disableMyLocation()似乎不工作工作、MyLocationOverlay、disableMyLocation

2023-09-05 08:21:34 作者:终年不至的夏至

只是浪费3小时试图找出为什么GPS图标仍然显示在通知栏时,我的地图活动暂停。我已经把范围缩小到不​​得不与我使用的(我也有一个LocationListener的和GpsStatus.Listener)的MyLocationOverlay对象。

Just wasted 3 hours trying to figure out why the GPS icon is still showing up in the notification bar when my map activity is paused. I've narrowed it down to having to do with the MyLocationOverlay object I'm using (I also have a LocationListener and a GpsStatus.Listener).

@Override
protected void onPause() { 
super.onPause();
manager.removeUpdates(locListener);
manager.removeGpsStatusListener(statListener);    

myLocOverlay.disableMyLocation(); //!doesn't seem to work
myLocOverlay.disableCompass();    
}

如果任何人有任何想法,为什么发生这种情况,请帮助,所以我不拉我的头发了。我不能释放我的应用程序的电池耗尽的问题是这样的。

If anyone has any idea why this is happening please help so I don't pull all my hair out. I can't release my app with a battery draining issue like this.

推荐答案

问题是我的MyLocationOverlay对象的动初始化。错误的code:

Issue was in my initilization of the MyLocationOverlay Object. Wrong Code:

private void initMyLocation() {
   myLocOverlay = new MyLocationOverlay(this, mapView); //THIS SHOULD NOT BE HERE.      
   myLocOverlay.enableMyLocation();
   myLocOverlay.enableCompass();
   mapView.getOverlays().add(myLocOverlay);
}

我initMyLocation()函数被通过,我的code多次调用。调用此行:myLocOverlay =新MyLocationOverlay(本,图形页面);多次被创造未能与disableMyLocation()(我觉得...)。

My initMyLocation() function gets called multiple times through-out my code. Calling this line: myLocOverlay = new MyLocationOverlay(this, mapView); multiple times was creating multiple listeners that failed to be disabled with disableMyLocation() (i think...).

反正我感动的MyLocationOverlay初始化的onCreate(),现在它的作品。

Anyways I moved the MyLocationOverlay initialization to onCreate() and now it works.