【发布时间】:2014-05-04 18:49:53
【问题描述】:
我已经在我想要获取经度和纬度的地方完成了这段代码,但是使用网络提供商和 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) { } }
【问题讨论】:
-
Android 新版本中有一些东西...您使用的是设备还是模拟器。如果设备是什么版本。