【发布时间】:2020-12-10 15:53:04
【问题描述】:
我想检查我当前的纬度和经度。这段代码在模拟器上工作,但是当我在手机上检查时我有空。(android 10)
手机上的应用有定位权限。
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location!=null){
MyLong=location.getLongitude();
MyLat=location.getLatitude();
test.setText(MyLat+" " +MyLong);
}
else{
test.setText("null");
}
}
});
【问题讨论】:
-
您是否添加了必要的权限?