在locationManager.removeUpdates()之后,通过将locationManager设置为null,GPS图标仍然闪烁

Nul*_*ion 7 android geolocation locationmanager

我正在开发位置跟踪应用程序.但我停止通过做两件事来获得位置更新......

  1. locationManager.removeUpdates(本); 和
  2. 将locationManager引用设置为null.

这将停止获得我想要的位置坐标...

但问题是gps图标仍在闪烁..这将耗尽设备的电池.

所以请帮我停止这个GPS修复...

小智 11

如果在mapView中显示位置和/或指南针,则必须禁用它们.如果您不这样做,GPS仍然有效.

例如:

private MapView mapView;
private MyLocationOverlay Location;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frame_layout);

    mapView = (MapView) this.findViewById(R.id.mapView);
    Location = new MyLocationOverlay(this, mapView);
    Location.enableMyLocation();
    Location.enableCompass();
    mapView.getOverlays().add(Location);
}

@Override
public void onDestroy() {
    Location.disableMyLocation();
    Location.disableCompass();
}
Run Code Online (Sandbox Code Playgroud)

  • 这是我的答案.谢谢!对于更新的Google Maps api,我这样做:`map.setMyLocationEnabled(false);` (4认同)

Com*_*are 2

如果您在模拟器上进行测试,这是完全正常的行为。状态栏中的 GPS 图标永远不会消失。

如果您在硬件上对此进行测试,则要么您已requestLocationUpdates()多次调用(并且尚未删除其他更新),要么硬件上的其他东西可能正在使用 GPS。