java - 我无法在回调函数之外记录变量,该函数在 Android 中分配有其内部的值
问题描述
这是我为变量赋值的函数Place
:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
//check LocationPermission Granted
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
else
{
fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
try {
// This is the place where I am storing my lanlag object
place = new LatLng(location.getLatitude(), location.getLongitude());
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), "null refrence in result", Toast.LENGTH_SHORT).show();
}
}
});
}
// Here I am trying to log
Log.i("land and lon", String.valueOf(place.latitude)+" "+String.valueOf(place.longitude));
}
解决方案
推荐阅读
- python-3.x - Pandas 将名称和 IP 对齐到两个不同的列中
- rx-java - 用一个值初始化 RxJava 流
- java - UserRepository 在 @Autowired 中返回 null
- laravel - 自动备份 MySQL 数据库到谷歌驱动器
- azure - 在 Azure 自动化 Powershell 脚本中使用参数数组
- java - 如何在Android中保持从baseAdapter接收到的奇数个按钮为三角形?
- android - Android Studio 平台工具-无法下载 api 24/28
- node.js - 尝试使用 npm 命令安装任何软件包时出现错误
- vuejs2 - VeeValidate 不适用于内联编辑。我正在使用 v-for 和 v-if 进行内联编辑
- java - 模拟类在运行测试时从不总是给出空指针