MyLocationOverlay disableMyLocation() not seeming to work

坚强是说给别人听的谎言 提交于 2019-12-05 01:00:37

问题


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.


回答1:


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

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

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



来源:https://stackoverflow.com/questions/6515923/mylocationoverlay-disablemylocation-not-seeming-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!