【发布时间】:2015-08-20 07:21:26
【问题描述】:
我在 SO 上阅读了很多关于此主题的问答,但我不得不说它们都不起作用。
我的问题是,即使我启用了 GPS,我也无法获取位置,除非我打开 Google 地图并获取我的位置,然后返回应用程序,这绝对不是用户的选择。
我有以下函数来获取位置。
public Location getCurrentLocation() {
LocationManager locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location myLocation = locationManager.getLastKnownLocation(provider);
return myLocation;
}
关于如何解决这个问题,我有什么遗漏吗? 我也试过这个 http://developer.android.com/training/location/retrieve-current.html#last-known 但仍然返回 null。
提前致谢
【问题讨论】:
标签: android google-maps gps android-location