requestSingleUpdate不工作:(

时间:2014-05-08 11:34:46

标签: android locationmanager

我有以下代码:

SosServiceListener mlistener = new SosServiceListener(this);

manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

// getting network status
boolean isNetworkEnabled = manager.
                            isProviderEnabled(LocationManager.NETWORK_PROVIDER);

String provider;
if (isNetworkEnabled) {
    provider = LocationManager.NETWORK_PROVIDER;
} else {
    provider = LocationManager.GPS_PROVIDER;
}
manager.requestSingleUpdate(provider, mlistener, null);
manager.getLastKnownLocation(provider);

但是从不调用SosServiceListener :(任何想法为什么?

1 个答案:

答案 0 :(得分:0)

String provider;
if (isNetworkEnabled) {
    provider = LocationManager.NETWORK_PROVIDER;
} else {
    provider = LocationManager.GPS_PROVIDER;
}

在设备上启用GPS,在移动设置的安全部分设置了卫星选项吗?因为你假设启用了GPS_PROVIDER,只是因为禁用了NETWORK_PROVIDER?这不准确......

同样manager.getLastKnownLocation(provider);将直接返回Location对象,并且不会在listenet中调用回调方法......

所以你需要使用其中任何一个......