我已经在想要获取经度和纬度的地方完成了这段代码,但是使用网络提供商和 gps 提供商我得到了我的位置 null 。即使启用了gps……为什么会这样?
boolean isGPSEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = lm .isProviderEnabled(LocationManager.NETWORK_PROVIDER); Location location = null; if (!isGPSEnabled && !isNetworkEnabled) { } else if(isGPSEnabled ) { location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(location == null) { if(isNetworkEnabled) location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if(location == null) { } } } else if(isNetworkEnabled){ location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if(location == null) { } }