【发布时间】:2014-10-17 12:35:11
【问题描述】:
我尝试使用MyCustomLocationListener 获取设备当前位置。
我的代码在这里通过,表明 GPS 和网络提供商都可用。
// getting GPS status
isGPSEnabled = androidLocationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = androidLocationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
Log.e(MyLogger.TAG, "Non providers are enabled");
showEnableGpsDialog();
return;
}
if (isGPSEnabled) {
androidLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0,
saveToSharedPrefListener);
Log.d(MyLogger.TAG, "GPS Enabled");
}
if (isNetworkEnabled) {
if (androidLocationManager == null) {
androidLocationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0,
saveToSharedPrefListener);
Log.d(MyLogger.TAG, "Network Enabled");
}
}
但是当我在室内时,永远不会调用 onLocationChanged。
只有当我使用Fake GPS 应用程序时,才会调用onLocationChanged。
我怎样才能写一个回退(不超时)来强制调用onLocationChanged
我曾经使用另一个 API requestSingleUpdate :
这两者在室内工作方面有什么区别?
if (isGPSEnabled) {
androidLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0,
saveToSharedPrefListener);
Log.d(MyLogger.TAG, "GPS Enabled");
}
和
if (BaseApplication.getCurrentActivity() != null) {
locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER,
saveToSharedPrefListener, BaseApplication.getCurrentActivity()
.getMainLooper());
【问题讨论】: