我需要当前位置,所以我使用了 FusedLocationProviderClient getLastLocation()。但它总是第一次为空。我该如何处理?这是代码
private FusedLocationProviderClient mFusedLocationClient;
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getApplicationContext());
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mFusedLocationClient.getLastLocation().addOnSuccessListener(location -> {
if (location != null) {
String latitude = String.valueOf(location.getLatitude());
String longitude = String.valueOf(location.getLongitude());
sendAddress(addressId,mTicketId,latitude,longitude,mCurrentTime);
}
});
}