【发布时间】:2015-05-04 15:27:52
【问题描述】:
我正在尝试按如下方式检索位置:
LocationManager locationManager = (LocationManager)MyApp.getAppContext().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
// Getting the name of the provider that meets the criteria
String provider = locationManager.getBestProvider(criteria, false);
if(provider!=null && !provider.equals("")){
// NOTE: the location below is null !!
Location location = locationManager.getLastKnownLocation(provider);
String lat = location.getLatitude();
String lng = location.getLongitude();
}
上面的“位置”为空。为什么?
但是当我打开 (Google) Maps 应用程序时 - 它会正确显示位置,甚至会显示通知图标(看起来像感叹号)。
还有一个 GPS 坐标应用程序 - 它也显示为空白。
我已在手机上打开“设置”>“位置”。如果重要的话,这是 Android 4.4.4 Sony Experia 手机。
【问题讨论】:
-
Francesco> 谢谢.. 但是使用 Google Play 服务而不是 Android 位置服务(我正在做的方式)更好吗?
标签: android gps geolocation