【发布时间】:2014-09-02 18:56:26
【问题描述】:
我想让当前位置同时使用在线或离线 GPS 以及 GPS 的预期行为是: 1.如果wifi或3g网络可用,它将使用它们来获取GPS位置。 2. 如果没有 wifi 或 3g 网络可用,它将使用平板电脑的离线 GPS(如果存在) 3. 如果什么都没有,它会显示错误信息。
我尝试了很多但还没有成功。我总是启用网络。
public boolean isGPSEnabled() {
Location location = null;
try {
mLocationManager = (LocationManager) getApplicationContext()
.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = mLocationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = mLocationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
return false;
}
} catch (Exception e) {
toast("Exception " + e.toString());
}
return true;
}
如果有人有想法。请帮忙。提前致谢
【问题讨论】: