0

Im using MyLocationOverlay to get my location. But i would like to stop GPS onPause and resume it onResume. How can i do that ?

I know for LocationManager is method removeUpdates...

final MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
myLocationOverlay.enableMyLocation();
mapView.getOverlays().add(myLocationOverlay); 

locButton.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
        myLocationOverlay.runOnFirstFix(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                mapView.getController().animateTo(myLocationOverlay.getMyLocation());
            }
        });{

        }
    }
});
4

2 回答 2

0

在您暂停的活动中:

@Override public void onPause() {
    myLocationOverlay.disableMyLocation();
    super.onPause();
}
@Override public void onResume() {
    myLocationOverlay.enableMyLocation();
    super.onResume();
}

但我还没有编译。来自https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/MyLocationOverlay

于 2012-11-26T21:43:02.483 回答
0

MyLocationOverlay创建对象时保留对对象的引用,并分别使用和中的enableMyLocation()disableMylocation()方法。根据您设置代码的方式,您可能需要在调用叠加层上的任何内容之前进行检查。onResume()onPause()null

于 2012-11-26T21:43:37.143 回答