我正在开发安卓应用程序。我陷入了困境。
getLastKnownLocation(provider)
Android 版本 4.1.1返回null
,而对于其他版本则很好。提供程序已启用,其余正常。我不知道问题出在哪里。这是代码。
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
location = locationManager.getLastKnownLocation(provider);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
mMap.clear();
System.out.println("Current Location = "+latLng);