MyLocationOverlay not calling onProviderDisabled

久未见 提交于 2020-01-06 06:54:30

问题


This is my code that behaves a little strange:

locationOverlay = new MyLocationOverlay(this, map) {
    @Override
    public void onLocationChanged(Location location) {
        super.onLocationChanged(location);
        updatePosition(locationOverlay.getMyLocation());
    }

    @Override
    public void onProviderDisabled(String provider) {
        if(provider.equals(LocationManager.GPS_PROVIDER))
            showNoGPSWarning();
    }
};

showNoGPSWarning shows a Dialog that asks if GPS should be enabled (like this).
Everything wokrs perfectly fine except if I start the Activity with GPS disabled and press "No" in the showNoGPSWarning() dialog. Then my App doesn't listen to GPS changes at all.

If I turn it on, nothing happens. The Google maps API doesn't try to get a GPS signal. If I turn it back off, nothing happens again, onProviderDisabled() is not called.
As I said, this is the only way that happens, if I press "Yes" in the dialog it works.
So how is my dialog affecting the behavior of my App?.


回答1:


Once again try to request for location updates when you press yes/no like below. Hope it helps.

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 2000.0f, myLocationListener);


来源:https://stackoverflow.com/questions/12159524/mylocationoverlay-not-calling-onproviderdisabled

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