android如何停止gps

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2012870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:12:27  来源:igfitidea点击:

android how to stop gps

androidgps

提问by d-man

After launching listener by the following code is working fine.

通过以下代码启动侦听器后工作正常。

LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
                    LocationManager.GPS_PROVIDER, WLConstants.DELAY_HOUR, gpsl
                            .getMinDistance(), gpsl);

After some time i stop the listener by the following code

一段时间后,我通过以下代码停止侦听器

locationManager.removeUpdates(this);

but problem is it still searching my gps any solution ??? how to stop gps ?

但问题是它仍在搜索我的 GPS 有什么解决方案吗???如何停止GPS?

回答by Jeff Gilfelt

You need to pass the same object implementing LocationListener that you requested location updates for to the locationManager.removeUpdates() method.

您需要将实现您请求位置更新的 LocationListener 的同一对象传递给 locationManager.removeUpdates() 方法。

So in unless thisand gpslare one and the same, you should call:

所以在除非thisgpsl是一回事,你应该调用:

locationManager.removeUpdates(gpsl);

回答by Claw Hammer

If you are using maps, you have to do:

如果您使用地图,则必须执行以下操作:

locationManager.removeUpdates(locationListener);

mMap.setMylocationEnabled(false);

回答by kevin Zhang

You could pass the parameter like this GPSLocationListener.this

您可以像这样传递参数 GPSLocationListener.this

locationManager.removeGpsStatusListener(GPSLocationListener.this);

the compile will not be wrong

编译不会出错

回答by d-man

My listener implemention

我的监听器实现

public class GPSLocationListener extends Activity implements LocationListener {

    @Override
        public void onLocationChanged(Location location) {
//code here
    }

    }

when i try to remove listener using follwing code compile time error.

当我尝试使用以下代码编译时错误删除侦听器时。

locationManager.removeGpsStatusListener(GPSLocationListener )

回答by Stelian Iancu

You have to pass the instance to your GPSLocationListenergo the removeGpsStatusListenermethod and not the class name.

您必须将实例传递给您GPSLocationListenerremoveGpsStatusListener方法而不是类名。